come scrivere XSD per il seguente codice XML?
-
12-10-2019 - |
Domanda
<?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>
Qui ho generare il XSD per sopra xml, ma non è stato corretto. mi potete aiutare a generare la XSD per l'XML? grazie in anticipo.
Soluzione
Basta eseguire l'utilità xsd.exe
(vedi: MSDN XML Schema Definition strumento ) su questo file XML, e si ottiene la risposta:
<?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>
Allora, qual è non è corretto di questo XSD ?? I tentativi xsd.exe
di indovinare che cosa il vostro XML conterrà, ma in diversi casi, si deve solo fare alcune ipotesi, quindi questo risultato potrebbe XSD o potrebbe non essere esattamente quello che ti serve, e potrebbe sicuramente essere scritto più bello / più efficiente, se avete ulteriore know-how circa la struttura del file XML. Per esempio. se si so che c'è sempre sta per essere solo un singolo elemento <table>
, si potrebbe rendere le cose molto più facile.