我正在尝试使用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.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>
我的xml:
<?xml version="1.0" encoding="UTF-8" ?>
<myservices:MyServices xmlns:nc="http://niem.gov/niem/niem-core/2.0"
xmlns:niem-xsd="http://niem.gov/niem/proxy/xsd/2.0" xmlns:myservices="http://myservices.com/myservices/1.0"
xmlns:s="http://niem.gov/niem/structures/2.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="MyServices.xsd">
<nc:DocumentFileControlID>20130904-1114.453</nc:DocumentFileControlID>
<nc:DocumentCreationDate>
<nc:Date>2013-09-04</nc:Date>
</nc:DocumentCreationDate>
</myservices:MyServices>
使用SchemaFactory验证时出现的错误是:
Reason: cvc-complex-type.2.1: Element 'nc:DocumentCreationDate' must have no character or element information item [children], because the type's content type is empty.
但在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>
答案 0 :(得分:0)
对于未列为问题一部分的其他导入XSD有很多参考。这使得很难确定哪里出错,但有一个问题是XML文件的xsi:schemaLocation
应该是名称空间-URI对,而不仅仅是URI:
xsi:schemaLocation="http://myservices.com/myservices/1.0 MyServices.xsd"
如果这还不足以解决您的问题,我建议修剪xsd:imports
并在您的答案中包含ComplexObjectType
等基本类型定义,以便我们拥有完整的用于帮助您解决验证问题的定义。