【问题标题】:Creating a SINGLE XSD schema file from an XML file?从 XML 文件创建一个 XSD 模式文件?
【发布时间】:2010-08-08 11:30:28
【问题描述】:

有没有办法从下面的 XML 文件中只创建一个 XSD 文件?我尝试了各种工具,但它们都生成了多个 XSD 文件。多个 XSD 文件的原因是什么?我只需要一个 XSD 文件就可以在 SSIS 中加载。

<xml xmlns:s='uuid:BDC6E3F0-6DA3-11d1-A2A3-00AA00C14882'
    xmlns:dt='uuid:C2F41010-65B3-11d1-A29F-00AA00C14882'
    xmlns:rs='urn:schemas-microsoft-com:rowset'
    xmlns:z='#RowsetSchema'>
<s:Schema id='RowsetSchema'>
    <s:ElementType name='row' content='eltOnly'>
        <s:AttributeType name="c0" rs:name="FIRST_NAME" rs:number="1" rs:nullable="true">
            <s:datatype dt:type="string" rs:dbtype="str" dt:maxLength="30"/>
        </s:AttributeType>
        <s:AttributeType name="c1" rs:name="MIDDLE_NAME" rs:number="2" rs:nullable="true">
            <s:datatype dt:type="string" rs:dbtype="str" dt:maxLength="30"/>
        </s:AttributeType>
        <s:AttributeType name="c2" rs:name="LAST_NAME" rs:number="3">
            <s:datatype dt:type="string" rs:dbtype="str" dt:maxLength="60" rs:maybenull="false"/>
        </s:AttributeType>
        <s:AttributeType name="c3" rs:name="OTHER_ID" rs:number="4" rs:nullable="true">
            <s:datatype dt:type="string" rs:dbtype="str" dt:maxLength="24"/>
        </s:AttributeType>
        <s:AttributeType name="c4" rs:name="FS_LUN_CODE_ID" rs:number="5" rs:nullable="true">
            <s:datatype dt:type="string" rs:dbtype="str" dt:maxLength="2"/>
        </s:AttributeType>
        <s:AttributeType name="c5" rs:name="FS_NAME_ID_PAYOR" rs:number="6" rs:nullable="true">
            <s:datatype dt:type="int" dt:maxLength="4" rs:precision="10" rs:fixedlength="true"/>
        </s:AttributeType>
        <s:AttributeType name="c6" rs:name="FS_TRAN_TIME" rs:number="7" rs:nullable="true">
            <s:datatype dt:type="int" dt:maxLength="4" rs:precision="10" rs:fixedlength="true"/>
        </s:AttributeType>
        <s:AttributeType name="c7" rs:name="NAME_ID" rs:number="8">
            <s:datatype dt:type="int" dt:maxLength="4" rs:precision="10" rs:fixedlength="true" rs:maybenull="false"/>
        </s:AttributeType>
        <s:AttributeType name="c8" rs:name="FS_TRAN_DATE" rs:number="9" rs:nullable="true">
            <s:datatype dt:type="date" dt:maxLength="6" rs:fixedlength="true"/>
        </s:AttributeType>
        <s:extends type="rs:rowbase"/>
</s:ElementType>
</s:Schema>
<rs:data>
    <z:row c0='SHELLI' c1='A' c2='AANENSON' c3='671590' c4='N' c5='0' c6='32885' c7='12' c8='2007-09-11'/>
    <z:row c0='SHELLI' c1='A' c2='AANENSON' c3='671590' c4='N' c5='0' c6='32885' c7='12' c8='2007-09-11'/>
    <z:row c0='SHELLI' c1='A' c2='AANENSON' c3='671590' c4='N' c5='0' c6='32885' c7='12' c8='2007-09-11'/>
    <z:row c0='SHELLI' c1='A' c2='AANENSON' c3='671590' c4='N' c5='0' c6='32885' c7='12' c8='2007-09-11'/>
    <z:row c0='WILLIAM' c1='' c2='AASEN' c3='916031' c4='N' c5='0' c6='55833' c7='13' c8='2007-07-27'/>
    <z:row c0='WILLIAM' c1='' c2='AASEN' c3='916031' c4='N' c5='0' c6='55833' c7='13' c8='2007-07-27'/>
    <z:row c0='WILLIAM' c1='' c2='AASEN' c3='916031' c4='N' c5='0' c6='55833' c7='13' c8='2007-07-27'/>
</rs:data>
</xml>

【问题讨论】:

    标签: xml xsd


    【解决方案1】:

    多个 XSD 文件的原因是您有两个架构命名空间:

    uuid:BDC6E3F0-6DA3-11d1-A2A3-00AA00C14882
    uuid:C2F41010-65B3-11d1-A29F-00AA00C14882
    

    这些命名空间中的每一个都将在单独的 xsd 架构文件中定义 - 我不知道有任何组合这两个架构文件的方式(即,让一个 xsd 架构针对多个命名空间)。

    可以将许多模式文件组合成一个模式集,但我不确定如何使用 SSIS 来做到这一点。

    对您来说更简单的解决方案可能是组合命名空间而不是拥有两个命名空间。

    【讨论】:

    • 谢谢,但是我该如何组合这两个命名空间呢?目前一个用于“s”,另一个用于“dt”。
    • @salvationishere - 结合我的意思是摆脱一个命名空间(例如,带有“dt”前缀的那个)并使用现有的命名空间/前缀。但是,根据您的数据,这可能不是一种合适的方法。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-10-05
    • 1970-01-01
    • 2021-02-16
    相关资源
    最近更新 更多