Good day! There is an xml file with a trace. content:

<?xml version='1.0' encoding='UTF-8'?> <packet timestamp='2012-02-13 12:50:11.269146' id='97b20aee-5606-11e1-a55c-0050fc9bb1bb'> <opensession> ... </opensession> </packet> 

But the <packet> element can contain either an embedded <opensession> element or a <closesession> .

Tell me, please, how to describe it in XML Schema?

At the moment there is a valid.xsd trace. content:

 <?xml version="1.0" encoding="utf-8"?> <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"> <xsd:element name="packet" type="PacketType"/> <xsd:complexType name="PacketType"> <xsd:attribute name="timestamp" type="xsd:date"/> <xsd:attribute name="id" type="xsd:string"/> </xsd:complexType> </xsd:schema> 

Thank.

    1 answer 1

    Everything turned out to be quite simple:

     ... <xsd:choise> <xsd:element name="one" /> <xsd:element name="two" /> ... </xsd:choice> ... 

    <choise> - Allows a single element of the selected group to be present in the container element.

    PS A good reference in Russian. XML Schema Language (XSD) can be found here .