【问题标题】:Different .xsd using xsd.exe and VisualStudio->Xml->CreateSchema使用 xsd.exe 和 VisualStudio->Xml->CreateSchema 的不同 .xsd
【发布时间】:2013-07-20 02:03:58
【问题描述】:

我有 foo.xml,我想生成 foo.xsd,因为它是用 VisualStudio->Xml->CreateSchema 生成的,试过 xsd.exe 但结果不一样。 (xsd.exe foo.xml)

如何从命令行调用与 VisualStudio->Xml->CreateSchema 相同的命令?

也许一个小例子会有所帮助,注意type="xs:string" minOccurs="0" 当 xml 更复杂时,差异会变得很大。

xml:

<foo>
  <x />
  <y />
</foo>

VS:

<?xml version="1.0" encoding="utf-8"?>
<xs:schema attributeFormDefault="unqualified" elementFormDefault="qualified" xmlns:xs="http://www.w3.org/2001/XMLSchema">
  <xs:element name="foo">
    <xs:complexType>
      <xs:sequence>
        <xs:element name="x" />
        <xs:element name="y" />
      </xs:sequence>
    </xs:complexType>
  </xs:element>
</xs:schema>

xsd.exe

<?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">
  <xs:element name="foo">
    <xs:complexType>
      <xs:sequence>
        <xs:element name="x" type="xs:string" minOccurs="0" />
        <xs:element name="y" type="xs:string" minOccurs="0" />
      </xs:sequence>
    </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="foo" />
      </xs:choice>
    </xs:complexType>
  </xs:element>
</xs:schema>

【问题讨论】:

  • 我以前没有经历过这种情况。 CreateSchemaxsd.exe的XSD怎么不一样?
  • @psubsee2003 如果你以前没有经历过这个,我猜你以前没有尝试过这个,或者你正在为 xsd.exe 使用其他选项;)我在 VS2005 中注意到了很长时间以前,我在 VS 2012 中再次看到它。请参阅更新。

标签: visual-studio visual-studio-2012 xsd xsd.exe


【解决方案1】:

看起来可能是 Visual Studio 在内部使用 XmlSchemaInference.InferSchema 而不是 xsd.exe?更多信息XmlSchemaInference.InferSchema.

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-05-20
    • 2011-11-08
    • 2011-05-18
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多