哪位高手会XML?请教XDR验证XML问题
okcat 2010-03-03 04:52:42 这是验证代码
<%@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.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.XML时报错:
打开输入文件错误: 'xmlschema.xdr'。架构中根元素的错误定义。处理资源 'http://127.0.0.1/aspnet/xmlschema.xdr' 时出错。第 2 行,位置: 98
<schema xmlns="urn:schemas-microsoft-com:xml-data" xmlns:dt="urn:schema-microsoft-com:datatypes">
----------------...