我正在尝试使用 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>