我正在进行XML分配,并且很难搞清楚它。
基本上我正在创建我的第一个Schema,我无法弄清楚如何将各个命名空间链接为名称。现在我有:
<xs:element name="dist:name" type="xs:string" />
不幸的是,该错误导致名称无效NCName。如果我删除命名空间它工作正常,但与我的XML文档中的其他东西冲突。
我搜索了几个小时,但找不到解决方法。这是我的XML和我的XSD的代码,如果有帮助的话。
XML:
<?xml-stylesheet type="text/xsl" href="first.xsl"?>
<compPress
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="urn:schema"
xsi:schemaLocation="urn:schema first.xsd">
<dist:distributor xmlns:dist="http://comppress.com/distributors">
<dist:name>MetED</dist:name>
<dist:id>365782</dist:id>
<dist:description></dist:description>
<dist:contractDate></dist:contractDate>
<dist:address></dist:address>
<dist:contactName>Mark</dist:contactName>
<dist:serviceRegion>Northeast</dist:serviceRegion>
</dist:distributor>
<div:division xmlns:div="http://comppress.com/divisions">
<div:name>Penguin</div:name>
<div:number>9</div:number>
<div:description></div:description>
<div:numberEmployees>76</div:numberEmployees>
<div:creationDate>Feb 1, 2014</div:creationDate>
<div:mission></div:mission>
</div:division>
<pub:publication xmlns:pub="http://comppress.com/publications">
<pub:name>Everwhere Media</pub:name>
<pub:id>GF0755</pub:id>
<pub:number></pub:number>
<pub:countPrinted>172</pub:countPrinted>
<pub:distributorsSent></pub:distributorsSent>
<pub:description></pub:description>
<pub:creationDate></pub:creationDate>
<pub:lastPrinted>Jan 17, 2016</pub:lastPrinted>
<pub:purpose></pub:purpose>
</pub:publication>
</compPress>
XSD:
<xs:schema
xmlns:xs="http://www.w3.org/2001/XMLSchema"
targetNamespace="urn:schema"
elementFormDefault="qualified">
<xs:element name="compPress">
<xs:complexType>
<xs:sequence>
<xs:element name="dist:distributor">
<xs:complexType>
<xs:sequence>
<xs:element name="dist:name" type="xs:string" />
<xs:element name="dist:id" type="xs:string" />
<xs:element name="dist:description" type="xs:string" />
<xs:element name="dist:contractDate" type="xs:string" />
<xs:element name="dist:address" type="xs:string" />
<xs:element name="dist:contactName" type="xs:string" />
<xs:element name="dist:serviceRegion" type="xs:string" />
</xs:sequence>
<xs:attribute name="xmlns:dist" type="xs:string" />
</xs:complexType>
</xs:element>
<xs:element name="div:division">
<xs:complexType>
<xs:sequence>
<xs:element name="div:name" type="xs:string" />
<xs:element name="div:number" type="xs:string" />
<xs:element name="div:description" type="xs:string" />
<xs:element name="div:numberEmployees" type="xs:string" />
<xs:element name="div:creationDate" type="xs:string" />
<xs:element name="div:mission" type="xs:string" />
</xs:sequence>
<xs:attribute name="xmlns:div" type="xs:string" />
</xs:complexType>
</xs:element>
<xs:element name="pub:publication">
<xs:complexType>
<xs:sequence>
<xs:element name="pub:name" type="xs:string" />
<xs:element name="pub:id" type="xs:string" />
<xs:element name="pub:number" type="xs:string" />
<xs:element name="pub:countPrinted" type="xs:string" />
<xs:element name="pub:distributorsSent" type="xs:string" />
<xs:element name="pub:description" type="xs:string" />
<xs:element name="pub:creationDate" type="xs:string" />
<xs:element name="pub:lastPrinted" type="xs:string" />
<xs:element name="pub:purpose" type="xs:string" />
</xs:sequence>
<xs:attribute name="xmlns:pub" type="xs:string" />
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
我花了很多时间试图解决这个问题,非常感谢任何帮助。