Page 1 of 1

Generate xsd from two xml events with different children

Posted: Mon May 19, 2008 2:26 am
by tsbasha
I have the following two different xml events that I get:

<ip ipAddress="1.1.1.1" timestamp="2008/05/13 16:57:13.870197">
<ipCreate device="24"/>
</ip>

<ip ipAddress="1.1.1.1" timestamp="2008/05/13 16:57:13.870197">
<ipDelete device="24"/>
</ip>

The <ip> element can have either <ipCreate> or <ipDelete> sub element, but not both. I've tried to combine both xml events into one file and tried to generate an xsd for them, but I get an error that is not mell-formed. Is there a way to generate one xsd file for both events?

Thanks,
tsbasha

Re: Generate xsd from two xml events with different children

Posted: Mon May 19, 2008 5:31 pm
by sorin_ristache
Hello,

Create a file on disk event1.xml with the content:

Code: Select all

<ip ipAddress="1.1.1.1" timestamp="2008/05/13 16:57:13.870197">
<ipCreate device="24"/>
</ip>
and a file event2.xml with the content:

Code: Select all

<ip ipAddress="1.1.1.1" timestamp="2008/05/13 16:57:13.870197">
<ipDelete device="24"/>
</ip>
Go to menu Tools -> Trang Converter, select XML Documents in the Input panel, press the Add button and add the files event1.xml and event2.xml to the file list, select W3C XML Schema in the Output panel, select the output file name, press the Convert button. The result XML Schema will define a root element ip with a choice content model like the following which means that an element ip can contain either an element ipCreate or an element ipDelete:

Code: Select all

  <xs:element name="ip">
<xs:complexType>
<xs:choice>
<xs:element ref="ipCreate"/>
<xs:element ref="ipDelete"/>
</xs:choice>
<xs:attribute name="ipAddress" use="required" type="xs:NMTOKEN"/>
<xs:attribute name="timestamp" use="required"/>
</xs:complexType>
</xs:element>
Regards,
Sorin

Re: Generate xsd from two xml events with different children

Posted: Tue May 20, 2008 2:25 am
by tsbasha
Thanks alot Sorin for your help.

That worked for me.

Best regards,
tsbasha