简体   繁体   中英

how to write xsd for the following xml?

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

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. Eg if you know that there's always going to be just a single <table> element, you could make things a lot easier.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM