Xml NIEM定义类型的XSD验证问题
我正在尝试使用NIEM元素创建一个模式,但在验证它时遇到了困难 我的模式:Xml NIEM定义类型的XSD验证问题,xml,xsd,Xml,Xsd,我正在尝试使用NIEM元素创建一个模式,但在验证它时遇到了困难 我的模式: <?xml version="1.0" encoding="UTF-8"?> <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns="http://myservices.com/myservices/1.0" targetNamespace="http://myservices.co
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns="http://myservices.com/myservices/1.0"
targetNamespace="http://myservices.com/myservices/1.0"
xmlns:myservices="http://myservices.com/myservices/1.0"
xmlns:nc="http://niem.gov/niem/niem-core/2.0"
xmlns:msdata="urn:schemas-microsoft-com:xml-msdata"
xmlns:i="http://niem.gov/niem/appinfo/2.0"
xmlns:s="http://niem.gov/niem/structures/2.0"
elementFormDefault="qualified">
<xs:import schemaLocation="niem/niem-core/2.0/niem-core.xsd" namespace="http://niem.gov/niem/niem-core/2.0"/>
<xs:element name="MyServices" msdata:Prefix="myservices">
<xs:complexType>
<xs:sequence>
<xs:element ref="nc:DocumentFileControlID" minOccurs="0" msdata:Ordinal="0" />
<xs:element ref="nc:DocumentCreationDate"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
但是在niem-core.xsd中,类型被定义为nc:DateType。如果我尝试将该类型添加到模式中的元素中,我会收到一个错误,说我不能在元素中包含类型
这是niem-core.xsd:
<?xml version="1.0" encoding="UTF-8"?>
<xsd:schema targetNamespace="http://niem.gov/niem/niem-core/2.0" version="1"
xmlns:s="http://niem.gov/niem/structures/2.0" xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:nc="http://niem.gov/niem/niem-core/2.0" xmlns:niem-xsd="http://niem.gov/niem/proxy/xsd/2.0"
xmlns:i="http://niem.gov/niem/appinfo/2.0">
<xsd:annotation>
<xsd:appinfo>
<i:ConformantIndicator>true</i:ConformantIndicator>
</xsd:appinfo>
</xsd:annotation>
<xsd:import schemaLocation="../../proxy/xsd/2.0/xsd.xsd" namespace="http://niem.gov/niem/proxy/xsd/2.0"/>
<xsd:import schemaLocation="../../appinfo/2.0/appinfo.xsd" namespace="http://niem.gov/niem/appinfo/2.0"/>
<xsd:import schemaLocation="../../structures/2.0/structures.xsd" namespace="http://niem.gov/niem/structures/2.0"/>
<xsd:complexType name="DateType">
<xsd:annotation>
<xsd:appinfo>
<i:Base i:namespace="http://niem.gov/niem/structures/2.0" i:name="Object"/>
</xsd:appinfo>
</xsd:annotation>
<xsd:complexContent>
<xsd:extension base="s:ComplexObjectType"/>
</xsd:complexContent>
</xsd:complexType>
<xsd:element name="DocumentCreationDate" type="nc:DateType"/>
<xsd:element name="DocumentFileControlID" type="niem-xsd:string" nillable="true"/>
</xsd:schema>
真的
有许多关于其他导入的XSD的参考文献没有作为问题的一部分列出。这使得很难确定到底出了什么问题,但有一个问题是XML文件的xsi:schemaLocation
应该是名称空间URI对,而不仅仅是URI:
xsi:schemaLocation="http://myservices.com/myservices/1.0 MyServices.xsd"
如果这还不足以解决您的问题,我建议删减xsd:imports
,并在您的答案中包含任何基本类型定义,例如ComplexObjectType
,以便我们有一套完整的定义来帮助您解决验证问题
<?xml version="1.0" encoding="UTF-8"?>
<xsd:schema targetNamespace="http://niem.gov/niem/niem-core/2.0" version="1"
xmlns:s="http://niem.gov/niem/structures/2.0" xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:nc="http://niem.gov/niem/niem-core/2.0" xmlns:niem-xsd="http://niem.gov/niem/proxy/xsd/2.0"
xmlns:i="http://niem.gov/niem/appinfo/2.0">
<xsd:annotation>
<xsd:appinfo>
<i:ConformantIndicator>true</i:ConformantIndicator>
</xsd:appinfo>
</xsd:annotation>
<xsd:import schemaLocation="../../proxy/xsd/2.0/xsd.xsd" namespace="http://niem.gov/niem/proxy/xsd/2.0"/>
<xsd:import schemaLocation="../../appinfo/2.0/appinfo.xsd" namespace="http://niem.gov/niem/appinfo/2.0"/>
<xsd:import schemaLocation="../../structures/2.0/structures.xsd" namespace="http://niem.gov/niem/structures/2.0"/>
<xsd:complexType name="DateType">
<xsd:annotation>
<xsd:appinfo>
<i:Base i:namespace="http://niem.gov/niem/structures/2.0" i:name="Object"/>
</xsd:appinfo>
</xsd:annotation>
<xsd:complexContent>
<xsd:extension base="s:ComplexObjectType"/>
</xsd:complexContent>
</xsd:complexType>
<xsd:element name="DocumentCreationDate" type="nc:DateType"/>
<xsd:element name="DocumentFileControlID" type="niem-xsd:string" nillable="true"/>
</xsd:schema>
xsi:schemaLocation="http://myservices.com/myservices/1.0 MyServices.xsd"