XML Schema for mixing generic and specific content

Is it possible to express as XML schema the following class of XML documents:
  • A root element "root" contains as first child precisely one element "message"
  • Subsequently, there may follow arbitrary further child elements, but no further "message" element
Example instances:\[code\]<root> <message type="S">Order saved</message> <order number="4711"/></root><root> <message type="S">3 countries selected</message> <country value="http://stackoverflow.com/questions/13700399/ES">Spain</country> <country value="http://stackoverflow.com/questions/13700399/FR">France</country> <country value="http://stackoverflow.com/questions/13700399/IT">Italy</country></root>\[/code\]My idea was to use a sequence of one \[code\]xs:element\[/code\] and \[code\]xs:any\[/code\], like so:\[code\]<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"> <xs:element name="root"> <xs:complexType> <xs:sequence> <xs:element name="message" maxOccurs="1"> <xs:complexType> <xs:simpleContent> <xs:extension base="xs:string"> <xs:attribute name="type"></xs:attribute> </xs:extension> </xs:simpleContent> </xs:complexType> </xs:element> <xs:any processContents="skip" maxOccurs="unbounded"/> </xs:sequence> </xs:complexType> </xs:element></xs:schema>\[/code\]But then, a document containing two "message" children would pass (since the second "message" element will comply with xs:any).
 
Back
Top