xsd.exe 生成两个文件,如何将它们合二为一? [英] xsd.exe generates two files, how to join them into one?

查看:33
本文介绍了xsd.exe 生成两个文件,如何将它们合二为一?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不是 XSD 专家..所以我使用 xsd.exe 快速生成一些我需要的 xsd,然后稍微调整它们(minOccur 等).

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).

但现在它已经创建了两个 XSD 文件,一个主要的,另一个定义了复杂类型的额外文件.我怎么能把它们混在一起?我已经尝试了一段时间,但我不断收到编译错误.

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.

以下是它们的样子:

<?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 文件只能描述一个命名空间,您展示了两个.

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.

唯一的方法是将所有内容都放在一个命名空间中,然后简单地将导入文件的内容复制到导入文件中;删除任何外部引用(xsd:import),应该这样做.但是,在这种情况下,您将无法验证开始时使用的内容...

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

这是单个命名空间 XSD 的样子:

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> 

我怎么强调这个 XSD 不会验证您使用 XSD.exe 来生成文件的源...

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

这篇关于xsd.exe 生成两个文件,如何将它们合二为一?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆