xsd.exe generates two files, how to join them into one?

折月煮酒 提交于 2019-12-22 12:20:10

问题


I'm not a big XSD expert.. so I'm using xsd.exe to quickly generate some xsd that I need and then tweaking them a bit (minOccur, etc).

But now it has created two XSD files, the main one and an extra one where it defines a complex type. How could I mash them together? I've tried for a while but I keep getting compilation errors.

Here's what they look like:

<?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>

and

<?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>

Thanks!


回答1:


Given the XSDs, and assuming you're trying to validate existing XML, you cannot convert to one file. There is only one namespace that can be described by an XSD file, and you're showing two.

The only way to do it would be to put everything in one namespace, and then simply copy the content of the imported file into the importing file; remove any external reference (the xsd:import) and that should do it. However, in this case you will not be able to validate what was used to begin with...

This is what a single namespace XSD would look like:

<?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> 

I cannot stress enough that this XSD would not validate the source you used with XSD.exe to generate the files...



来源:https://stackoverflow.com/questions/9675289/xsd-exe-generates-two-files-how-to-join-them-into-one

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!