XML schema validation question

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Antony

    #1

    XML schema validation question

    Hi there, I have defined an XML schema for some information I am going
    to import into a database.

    What I do not know how to do in the schema is to ensure if
    <numberOfItem s> is 6, then there has to be 6 entries of <item> under
    <listOfItems> . Currently I am having to do this in my (Java)
    application code.


    <dataToImport >
    <numberOfItems> 6</numberOfItems>
    <listOfItems>
    <item>GHY-098</item>
    <item>GHY-108</item>
    <item>GHY-109</item>
    <item>GHY-112</item>
    <item>GHY-113</item>
    <item>GHY-999</item>
    <listOfItems>
    </dataToImport>


    The XML above is valid when I put the following line in my schema

    <xsd:element name="item" minOccurs="6" maxOccurs="6">

    but not every <listOfItems> contains 6 <item> lines. I want a way of
    saying that the minOccurs and maxOccurs equal the value in
    <numberOfItems> , which in this case is 6 but also may be 8, or 4, or
    any other number.

    Can this be done in an XML Schema?

    Although it is probably in this book "XML in a Nutshell, a Desktop
    Quick Reference, 2nd Ed" I cannot find the information.

    Thank you
    Tony
  • Bob Foster

    #2
    Re: XML schema validation question

    minOccurs="6" maxOccurs="6"

    Bob Foster

    "Antony" <tonypeterson00 0001@hotmail.co m> wrote in message
    news:37ebdce4.0 308160106.7a32e e4b@posting.goo gle.com...[color=blue]
    > Hi there, I have defined an XML schema for some information I am going
    > to import into a database.
    >
    > What I do not know how to do in the schema is to ensure if
    > <numberOfItem s> is 6, then there has to be 6 entries of <item> under
    > <listOfItems> . Currently I am having to do this in my (Java)
    > application code.
    >
    >
    > <dataToImport >
    > <numberOfItems> 6</numberOfItems>
    > <listOfItems>
    > <item>GHY-098</item>
    > <item>GHY-108</item>
    > <item>GHY-109</item>
    > <item>GHY-112</item>
    > <item>GHY-113</item>
    > <item>GHY-999</item>
    > <listOfItems>
    > </dataToImport>
    >
    >
    > The XML above is valid when I put the following line in my schema
    >
    > <xsd:element name="item" minOccurs="6" maxOccurs="6">
    >
    > but not every <listOfItems> contains 6 <item> lines. I want a way of
    > saying that the minOccurs and maxOccurs equal the value in
    > <numberOfItems> , which in this case is 6 but also may be 8, or 4, or
    > any other number.
    >
    > Can this be done in an XML Schema?
    >
    > Although it is probably in this book "XML in a Nutshell, a Desktop
    > Quick Reference, 2nd Ed" I cannot find the information.
    >
    > Thank you
    > Tony[/color]


    Comment

    Working...