请教XML与模式
okcat 2010-03-02 10:57:38 谁帮我看看啊.可以在自己机子上调试下...........
这是验证代码
<%@page language="vb"%>
<%@import namespace="system.xml"%>
<%@import namespace="system.xml.schema"%>
<script runat="server">
dim xtr as xmltextreader
dim xvr as xmlvalidatingreader
sub page_load(ob as object,ev as eventargs)
try
xtr= new xmltextreader(server.mappath("xml.xml"))
xvr=new xmlvalidatingreader(xtr)
xvr.validationtype=validationtype.schema
addhandler xvr.validationeventhandler,addressof showerror
while xvr.read
end while
catch ex as exception
response.write("error accessing xml file")
finally
xtr.close
xvr.close
end try
end sub
sub showerror(ob as object,ev as validationeventargs)
response.write(" <font color='red'>" & ev.message & " </font> <br>")
response.write("line:" & xtr.linenumber & "position:" & xtr.lineposition)
end sub
</script>
<html>
<body>
</body>
</html>
xmlschema.xdr模式文件内容
<?xml version="1.0"?>
<schema xmlns="urn:schemas-microsoft-com:xml-data" xmlns:dt="urn:schemas-microsoft-com:xml-datatype">
<elementtype name="firstname" content="textonly"/>
<elementtype name="lastname" content="textonly/>
<elementtype name="author content="eltonly">
<element type="firstname"/>
<element type="lastname"/>
</elementtype>
<elementtype name="title" content="textonly" />
<elementtype name="price" content="textonly" dt:type="float"/>
<attributetype name="genre" dt:type="string"/>
<attributetype name="style" dt:type="enumeration" dt:value="paperback hardback"/>
<elementtype name="book" content="eltonly">
<element type="title"/>
<element type="author"/>
<element type="price"/>
</elementtype>
<elementtype name="bookstore" content="eltonly">
<element type="book"/>
</elementtype>
</schema>
XML文件
<?xml version="1.0"?>
<bookstore xmlns="x-schema:xmlschema.xdr">
<book>
<title>i am stuent </title>
<author>
<fristname>j </fristname>
<lastname>smith </lastname>
</author>
<price>25 </price>
</book>
</bookstore>
感觉是关联有问题
模式与XML文件关联后,执行验证,报错:
未能找到元素“x-schema:xmlschema.xdr:bookstore”的架构信息。
line:2position:2未能找到元素“x-schema:xmlschema.xdr:book”的架构信息。
line:3position:5未能找到元素“x-schema:xmlschema.xdr:title”的架构信息。
line:4position:8未能找到元素“x-schema:xmlschema.xdr:author”的架构信息。
line:5position:8未能找到元素“x-schema:xmlschema.xdr:fristname”的架构信息。
line:6position:11未能找到元素“x-schema:xmlschema.xdr:lastname”的架构信息。
line:7position:11未能找到元素“x-schema:xmlschema.xdr:price”的架构信息。
line:9position:8