Generate xsd from two xml events with different children

This should cover W3C XML Schema, Relax NG and DTD related problems.
tsbasha
Posts: 2
Joined: Mon May 19, 2008 2:12 am

Generate xsd from two xml events with different children

Post by tsbasha » Mon May 19, 2008 2:26 am

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

sorin_ristache
Posts: 4144
Joined: Fri Mar 28, 2003 2:12 pm

Re: Generate xsd from two xml events with different children

Post by sorin_ristache » Mon May 19, 2008 5:31 pm

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

tsbasha
Posts: 2
Joined: Mon May 19, 2008 2:12 am

Re: Generate xsd from two xml events with different children

Post by tsbasha » Tue May 20, 2008 2:25 am

Thanks alot Sorin for your help.

That worked for me.

Best regards,
tsbasha

Post Reply