Pregunta

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

Aquí i generar el xml xsd para arriba, pero no fue correcta. me pueden ayudar a generar el xsd para el XML? gracias de antemano.

¿Fue útil?

Solución

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.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top