CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Sep 2004
    Posts
    1

    Help, about Schema

    Hi ,

    I have an xml file which has the following requirement :

    A root node will have :
    i> one or more required nodes (can occurs 1 or n times) and
    ii> some optional nodes (can occurs 0 or 1 times) and
    iii> some optional nodes (can occurs 0 or n times) and
    iiii> all the nodes are in any orders.

    e.g.

    <root>
    <title>abc</title>
    <creator>benny</creator>
    <creator>danny</creator>
    <date>yyyy-mm-dd</date>
    </root>

    notes:
    the title node is a required node (occurs 1 or n times)
    the creator nodes are optional nodes (occurs 0 or n times)
    the date node is a node that cannot be repeated (occurs 0 or 1 times)
    all these nodes can list in any order.


    I'm not able to create a schema with the above restrction using the existing XSD indicaters( "All", "choice" or "sequence") .

    hope somebody can give me some idea

  2. #2
    Join Date
    Sep 2004
    Posts
    8

    Re: Help, about Schema

    The first part of your question talks about optional nodes (elements), but it is not clear if you have a specfic list of these, or if users could potentially have any named node.

    Its not possible to include unknown elements (nodes) in a Schema, so you will have to provide (in the Schema) every possible element name that you want to verify.

    If you only have a few named nodes, such as title, creator and date, then simply include them in the Schema. The required node needs minOccurs=1 and maxOccurs="unbounded". The optional nodes can have the minOccurs and maxOccurs set appropriately.

    Since the nodes can list in any order, you do not want a sequence, and you are not requiring every one, so All is not appropriate. What you do is to use choice, and treat each element type as a group, so that the different minOccurs and maxOccurs can be applied.

    How about this for your example:

    <xs:element name="root">
    <xs:complexType>
    <xs:choice minOccurs="1" maxOccurs="unbounded">
    <xs:choice maxOccurs="unbounded" minOccurs="1">
    <xs:element name="title" type="xs:string" />
    </xs:choice>
    <xs:choice minOccurs="0" maxOccurs="unbounded">
    <xs:element name="creator" type="xs:string" />
    </xs:choice>
    <xs:choice minOccurs="0" maxOccurs="1">
    <xs:element name="date" type="xs:string" />
    </xs:choice>
    </xs:choice>
    </xs:complexType>
    </xs:element>

    I'm no expert, so someone can corect me if its wrong, but why not try with a few sample files and see if it validates them?

  3. #3
    Join Date
    Sep 2005
    Posts
    2

    Re: Help, about Schema

    Dear Bennych and DVDcontrol,

    I am sorry to say that the given solution is not working.

    When i gave
    <root>
    <title>aa</title>
    <date>13092005</date>
    <date>14092005</date>
    </root>

    the schema is not rejecting. Two date elements should not be allowed.

    I am facing the same problem right now. If you already have any other solution please send me. Any help in this regard will be appreciated.

    Thanks in advance.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured