我不是一个 XSD 专家..所以我使用 xsd.exe 快速生成一些我需要的 xsd,然后对它们进行一些调整(minOccur 等)。
但现在它创建了两个 XSD 文件,一个是主文件,另一个是定义复杂类型的额外文件。我怎样才能把它们混在一起呢?我已经尝试了一段时间,但总是出现编译错误。
它们的样子是这样的:
<?xml version="1.0" encoding="utf-8"?>
<xs:schema id="NewDataSet" xmlns="" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata" xmlns:app1="urn:ietf:params:xml:ns:xmpp-bind">
<xs:import namespace="urn:ietf:params:xml:ns:xmpp-bind" schemaLocation="Binding_app1.xsd" />
<xs:element name="iq">
<xs:complexType>
<xs:sequence>
<xs:element ref="app1:bind" />
</xs:sequence>
<xs:attribute name="id" type="xs:string" />
<xs:attribute name="type" type="xs:string" />
<xs:attribute name="to" type="xs:string" />
</xs:complexType>
</xs:element>
<xs:element name="NewDataSet" msdata:IsDataSet="true" msdata:UseCurrentLocale="true">
<xs:complexType>
<xs:choice minOccurs="0" maxOccurs="unbounded">
<xs:element ref="iq" />
</xs:choice>
</xs:complexType>
</xs:element>
</xs:schema>
和
<?xml version="1.0" standalone="yes"?>
<xs:schema targetNamespace="urn:ietf:params:xml:ns:xmpp-bind" xmlns:mstns="urn:ietf:params:xml:ns:xmpp-bind" xmlns="urn:ietf:params:xml:ns:xmpp-bind" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata" attributeFormDefault="qualified" elementFormDefault="qualified" xmlns:app1="urn:ietf:params:xml:ns:xmpp-bind">
<xs:element name="bind">
<xs:complexType>
<xs:sequence>
<xs:element name="resource" type="xs:string" minOccurs="0" />
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
谢谢!
最佳答案
考虑到 XSD,并假设您正在尝试验证现有 XML,则无法转换为一个文件。 XSD 文件只能描述一个命名空间,而您显示了两个。
唯一的方法是将所有内容放在一个 namespace 中,然后只需将导入文件的内容复制到导入文件中;删除任何外部引用(xsd:import)就可以了。但是,在这种情况下,您将无法验证开始时使用的内容...
这就是单个命名空间 XSD 的样子:
<?xml version="1.0" encoding="utf-8"?>
<!--XML Schema generated by QTAssistant/XSR Module (http://www.paschidev.com)-->
<xs:schema id="NewDataSet" xmlns="" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata" xmlns:app1="urn:ietf:params:xml:ns:xmpp-bind">
<xs:element name="iq">
<xs:complexType>
<xs:sequence>
<xs:element ref="bind"/>
</xs:sequence>
<xs:attribute name="id" type="xs:string"/>
<xs:attribute name="type" type="xs:string"/>
<xs:attribute name="to" type="xs:string"/>
</xs:complexType>
</xs:element>
<xs:element name="NewDataSet" msdata:IsDataSet="true" msdata:UseCurrentLocale="true">
<xs:complexType>
<xs:choice minOccurs="0" maxOccurs="unbounded">
<xs:element ref="iq"/>
</xs:choice>
</xs:complexType>
</xs:element>
<xs:element name="bind">
<xs:complexType>
<xs:sequence>
<xs:element name="resource" type="xs:string" minOccurs="0"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
我必须强调的是,此 XSD 不会验证您与 XSD.exe 一起使用来生成文件的源...
关于xml - xsd.exe生成两个文件,如何将它们合并为一个?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9675289/