哪位高手会XML?请教XDR验证XML问题
这是验证代码
<%@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">
----------------...
<%@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">
----------------...
...全文
相关推荐
xdr.rar_x86_xml
标题中的"xdr.rar_x86_xml"暗示了这个压缩包可能包含与x86架构相关的XML文件,可能是用于PowerDesigner的资源。
2、XML数据验证及其应用场景
本文深入探讨了XML数据验证的重要性及其应用场景,详细介绍了DTD、XDR和XSD三种验证类型的特点及适用场景,并通过示例展示了如何使用XmlValidatingReader进行XML文档验证。此外,文章还讨论了XML命名空间和限定名的使用,以及在实际应用中的案例,如配置文件验证和Web服务请求验证。最后,提出了性能优化策略以应对大型XML文档验证时可能带来的性能开销问题。
XML---试题及答案
XML文档的验证可以通过DTD(文档类型定义)、XDR(XML数据简化)或XSD(XML架构定义)来确保文档结构的合法性。DTD是XML文档的一种验证方式,用于定义文档结构和元素规则。
用XSD完成xml有效性的验证
在开发过程中,验证XML文档的有效性是非常重要的一步,可以预防因数据格式错误导致的问题。在VS2005中,我们可以使用C#语言来实现XSD对XML的验证。
映射架构在SQL Server检索XML数据的应用.pdf
一个简单的XDR架构示例是:```xml<?xml version="1.0"?


