-- 作者:cwzb
-- 发布时间:1/27/2005 9:31:00 PM
-- XML命名空间引用,出现莫名错误,说我是没有申明类型或是缺少元素(请高人指点)
代码1: <?xml version="1.0" encoding="utf-8" ?> <ds:d-schema xmlns:ds="http://www.xsdml.net/2005/0125/d-schema.xsd"> <ds:element ds:name="姓名" ds:type="string" ds:minOccurs="1" /> <ds:element ds:name="出生年月" ds:minOccurs="1"> <ds:attribute ds:name="年" /> <ds:attribute ds:name="月" ds:type="string" /> <ds:attribute ds:name="日" ds:type="string" /> </ds:element> </ds:d-schema> 代码2: <?xml version="1.0" encoding="utf-8" ?> <d-schema xmlns="http://www.hoson.net/2005/0125/d-schema.xsd"> <element name="姓名" type="string" minOccurs="1" /> <element name="出生年月" type="string" minOccurs="1"> <attribute name="年" /> <attribute name="月" type="string" /> <attribute name="日" type="string" /> </element> </d-schema> // //其实是完全一样的代码,只是代码1用"ds作为命名空间前缀",而代码2使用默认的命名空间,但是代码1就验证通过,而代码2就会提示出错(.NET环境下验证),这至底是为什么? // 符上XSD文件: <?xml version="1.0" encoding="UTF-8" ?> <xs:schema id="d-schema" targetNamespace="http://www.xsdml.net/2005/0125/d-schema.xsd" xmlns="http://www.xsdml.net/2005/0125/d-schema.xsd" xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified" attributeFormDefault="qualified"> <xs:element name="d-schema"> <xs:complexType> <xs:choice maxOccurs="unbounded"> <xs:element ref="element" /> </xs:choice> </xs:complexType> </xs:element> <xs:element name="element"> <xs:complexType> <xs:sequence> <xs:element ref="attribute" minOccurs="0" maxOccurs="unbounded" /> <xs:element ref="element" minOccurs="0" maxOccurs="unbounded" /> </xs:sequence> <xs:attribute name="name" type="xs:ID" use="required" /> <xs:attribute name="type" type="xs:string" use="optional" /> <xs:attribute name="minOccurs" type="xs:integer" use="optional" default="1" /> <xs:attribute name="maxOccurs" type="xs:integer" use="optional" default="1" /> </xs:complexType> </xs:element> <xs:element name="attribute"> <xs:complexType> <xs:attribute name="name" type="xs:string" use="required" /> <xs:attribute name="type" type="xs:string" use="optional" /> </xs:complexType> </xs:element> </xs:schema>
|