下面的xml如何写xsd?

发布于 2024-10-08 15:06:57 字数 510 浏览 0 评论 0原文

   <?xml version="1.0"?>
   <datatype xmlns:xs="http://www.w3.org/2001/XMLSchema-instance"             
         xs:noNamespaceSchemaLocation="sampletype.xsd">
    <table name="emp">
      <columns>
       <column>
          <name>emp_id</name>
          <data_type>int(200) </data_type>
       </column>
      </columns>
     </table>
    </datatype>

这里我为上面的xml生成了xsd,但它不正确。你能帮我生成 xml 的 xsd 吗?提前致谢。

   <?xml version="1.0"?>
   <datatype xmlns:xs="http://www.w3.org/2001/XMLSchema-instance"             
         xs:noNamespaceSchemaLocation="sampletype.xsd">
    <table name="emp">
      <columns>
       <column>
          <name>emp_id</name>
          <data_type>int(200) </data_type>
       </column>
      </columns>
     </table>
    </datatype>

Here i generate the xsd for above xml, but it was not correct. can you help me generate the xsd for the xml? thanks in advance.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

何以笙箫默 2024-10-15 15:06:57

只需运行 xsd.exe 实用程序(请参阅:MSDN XML架构定义工具)对此 XML 文件进行分析,您会得到答案:

<?xml version="1.0" encoding="utf-8"?>
<xs:schema id="datatype" xmlns="" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
  <xs:element name="datatype" msdata:IsDataSet="true" msdata:Locale="en-US">
    <xs:complexType>
      <xs:choice minOccurs="0" maxOccurs="unbounded">
        <xs:element name="table">
          <xs:complexType>
            <xs:sequence>
              <xs:element name="columns" minOccurs="0" maxOccurs="unbounded">
                <xs:complexType>
                  <xs:sequence>
                    <xs:element name="column" minOccurs="0" maxOccurs="unbounded">
                      <xs:complexType>
                        <xs:sequence>
                          <xs:element name="name" type="xs:string" minOccurs="0" />
                          <xs:element name="data_type" type="xs:string" minOccurs="0" />
                        </xs:sequence>
                      </xs:complexType>
                    </xs:element>
                  </xs:sequence>
                </xs:complexType>
              </xs:element>
            </xs:sequence>
            <xs:attribute name="name" type="xs:string" />
          </xs:complexType>
        </xs:element>
      </xs:choice>
    </xs:complexType>
  </xs:element>
</xs:schema>

那么这个 XSD 有什么不正确? xsd.exe 尝试猜测您的 XML 将包含什么内容,但在某些情况下,它只需做出一些假设,因此生成的 XSD 可能正是您所需要的,也可能不是您所需要的,并且它可能如果您对 XML 结构有额外的了解,那么肯定会写得更好/更有效。例如,如果您知道总是只有一个 元素,那么您可以使事情变得容易得多。

Just run the xsd.exe utility (see: MSDN XML Schema Definition Tool) over this XML file, and you get your answer:

<?xml version="1.0" encoding="utf-8"?>
<xs:schema id="datatype" xmlns="" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
  <xs:element name="datatype" msdata:IsDataSet="true" msdata:Locale="en-US">
    <xs:complexType>
      <xs:choice minOccurs="0" maxOccurs="unbounded">
        <xs:element name="table">
          <xs:complexType>
            <xs:sequence>
              <xs:element name="columns" minOccurs="0" maxOccurs="unbounded">
                <xs:complexType>
                  <xs:sequence>
                    <xs:element name="column" minOccurs="0" maxOccurs="unbounded">
                      <xs:complexType>
                        <xs:sequence>
                          <xs:element name="name" type="xs:string" minOccurs="0" />
                          <xs:element name="data_type" type="xs:string" minOccurs="0" />
                        </xs:sequence>
                      </xs:complexType>
                    </xs:element>
                  </xs:sequence>
                </xs:complexType>
              </xs:element>
            </xs:sequence>
            <xs:attribute name="name" type="xs:string" />
          </xs:complexType>
        </xs:element>
      </xs:choice>
    </xs:complexType>
  </xs:element>
</xs:schema>

So what is not correct about this XSD ?? The xsd.exe attempts to guess what your XML will contain, but in several cases, it just has to make some assumptions, so this resulting XSD might or might not be exactly what you need, and it could definitely be written nicer/more efficiently, if you have additional know-how about the structure of the XML. E.g. if you know that there's always going to be just a single <table> element, you could make things a lot easier.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文