XML Schema: How to put restrictions on element names

Discussion in 'XML' started by ruediger, May 6, 2006.

  1. ruediger

    ruediger Guest

    Hi there,

    I want to set up an XML Schema for documents of the following
    structure:

    The <root> node contains
    - an optional <message> element with a text attribute, and
    - arbitrary further content.

    To make the parts unique, the top-level element of the further content
    must not have the name "message". Therefore, this further content is
    not completely arbitrary, but there is a restriction on the element
    name.

    Examples:

    <root>
    <message text="Hi there"/>
    <purchaseOrder number="4711">
    <item number="10" matnr="4033871" qty="10"/>
    </purchseOrder>
    </root>

    <root>
    <message text="Only message"/>
    </root>

    <root>
    <!-- only further content -->
    <part number="10">
    <option key="10" text="First option"/>
    <option key="20" text="Second option"/>
    </part>
    </root>

    In an imagined, non-existing XML Schema syntax, the further
    content should be defined somehow like

    <xs:restriction refType="xs:any">
    <xs:condition test="local-name()!='message'"/>
    </xs:restriction>

    Since I don't know how to do such a thing in the existing
    XML-Schema language, I tried to use <xs:any> without restrictions.
    But this didn't pass the XSD Validator, due to the non-uniqueness
    of a possible message element:

    <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
    <xs:element name="root">
    <xs:complexType>
    <xs:sequence>
    <xs:element name="message" minOccurs="0" maxOccurs="1">
    <xs:complexType>
    <!-- leaving out attribute definitions for simplicity... -->
    </xs:complexType>
    </xs:element>
    <xs:any minOccurs="0" processContents="skip"/>
    <!-- ^^^^^ For this part, we need a restriction on the element
    name!!! -->
    </xs:sequence>
    </xs:complexType>
    </xs:element>
    </xs:schema>

    Any suggestion how to define arbitrary elements
    with restricted element name in XML Schema???

    Thanks
    Ruediger
     
    ruediger, May 6, 2006
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Jean-Marie Condom
    Replies:
    2
    Views:
    418
    Jean-Marie Condom
    Nov 26, 2004
  2. Lewis G. Pringle, Jr.
    Replies:
    0
    Views:
    628
    Lewis G. Pringle, Jr.
    Sep 30, 2003
  3. Replies:
    2
    Views:
    529
  4. Paul Johnston

    Restrictions in XML Schema

    Paul Johnston, Nov 8, 2006, in forum: XML
    Replies:
    1
    Views:
    477
  5. sqlsurfing
    Replies:
    0
    Views:
    896
    sqlsurfing
    Jan 27, 2010
Loading...

Share This Page