哪位高手会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">
----------------...

...全文
68 2 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
okcat 2010-03-19
  • 打赏
  • 举报
回复
UP..........................
okcat 2010-03-03
  • 打赏
  • 举报
回复
up.................

8,909

社区成员

发帖
与我相关
我的任务
社区描述
XML/XSL相关问题讨论专区
社区管理员
  • XML/XSL社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧