2011-10-27 42 views
2

在C#类中使用xsd.exe,有​​没有办法用嵌套类型生成xsd文件,而不是全局类型?使用xsd.exe生成嵌套类型而不是全局类型

我想使用这个xsd文件,SSIS - Sql服务器集成服务,看看SSIS是不是很好的读我的xsd。

我想产生这样的XSD,与嵌套类型:

<?xml version="1.0" encoding="utf-8"?> 
<xs:schema targetNamespace="http://tempuri.org/XMLSchema.xsd" elementFormDefault="qualified" xmlns="http://tempuri.org/XMLSchema.xsd" xmlns:mstns="http://tempuri.org/XMLSchema.xsd" xmlns:xs="http://www.w3.org/2001/XMLSchema"> 
    <xs:element name="Country"> 
    <xs:complexType> 
     <xs:sequence> 
     <xs:element name="City"> 
      <xs:complexType> 
      <xs:sequence> 
       <xs:element name="CityName" type="xs:string" /> 
      </xs:sequence> 
      </xs:complexType> 
     </xs:element> 
     <xs:element name="CoutryName" type="xs:string" /> 
     </xs:sequence> 
    </xs:complexType> 
    </xs:element> 
</xs:schema> 

但XSD.EXE产生这种与全球类型和SSIS不读它。我需要手动将此xsd更改为如上所示。

<?xml version="1.0" encoding="utf-8"?> 
<xs:schema targetNamespace="http://tempuri.org/XMLSchema.xsd" elementFormDefault="qualified" xmlns="http://tempuri.org/XMLSchema.xsd" xmlns:mstns="http://tempuri.org/XMLSchema.xsd" xmlns:xs="http://www.w3.org/2001/XMLSchema"> 
    <xs:element name="Country"> 
    <xs:complexType> 
     <xs:sequence> 
     <xs:element name="City" type="City"> 
     </xs:element> 
     <xs:element name="CoutryName" type="xs:string" /> 
     </xs:sequence> 
    </xs:complexType> 
    </xs:element> 
    <xs:complexType name="City"> 
    <xs:sequence> 
     <xs:element name="CityName" type="xs:string" /> 
    </xs:sequence> 
    </xs:complexType> 
</xs:schema> 

有什么建议吗?或者我可以使用的其他工具。

非常感谢。

+0

您能否更具体地指出哪些“非常好”意味着什么,以及您尝试这种情况的环境?我假设它是一个数据流中的XML源;我已经尝试过2008 R2,并且我获得了两个XSD的相同结果。 –

+0

好的。 @PetruGardea就像你所设想的那样。数据流中的XML源。我认为SSIS没有将XSD与我的C#类生成的XML映射。我创建了一个WebService。 –

回答

3

我会进一步假设不是“很好”意味着你没有在你的XML源输出中看到CountryName。 关于MSDN的文档是一个很好的解读,尽管在我看来它没有描述为什么你会遇到你所看到的行为。

我相信它与XML源输出的确定方式有关。 SSIS从XML结构推断数据集;对应于根元素的顶层实体未映射到输出,因此与您关联的所有属性(在您的情况下为CountryName)都不会显示出来。

证明它的最简单方法是添加另一个封装您国家的根元素(相当于拥有一个具有Country-type属性的虚拟“根”类)。

<xs:element name="root"> 
    <xs:complexType> 
     <xs:sequence> 
      <xs:element ref="Country"/> 
     </xs:sequence> 
    </xs:complexType> 
</xs:element> 

如果添加上述模式片段到您的模式,你应该把你的预期效果。起初我认为它与here描述的问题有关;尽管您仍然可以使用该工具来查看上述MSDN链接中描述的数据集,但对于您的情况,您建议的创作风格(基本上为russian-doll)无法改变结果。

+0

谢谢@Petru Gardea。我做到了,工作得很好。谢谢。 –

相关问题