You are viewing a plain text version of this content. The canonical link for it is here.
Posted to j-users@xerces.apache.org by Benson Cheng <Be...@viacore.net> on 2001/05/08 18:36:25 UTC

Schema question

Hi,

I hava a schema question.  I need write a schema to validate the following
sample XML file, the key is that at least one <Group> node is exist, and at
least one of its <Id> is the "Invoice" value, other <Group>/<Id> could be
anything.  I think I need use "Choice", but not sure how to do it, any hint
will be help.


<?xml version="1.0" encoding="UTF-8" ?>
<Root>
  <Group>
     <Id>Invoice</Id>
     <value>123456</value>
  </Group>
  <Group>
     <Id>Anything1</Id>
     <value>99999</value>
  </Group>
  <Group>
     <Id>Anything2</Id>
     <value>888888</value>
  </Group>
</Root>

Thanks,
Benson.

---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-j-user-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-j-user-help@xml.apache.org


Re: Schema question

Posted by Chetan Chudasama <cc...@nms.fnc.fujitsu.com>.
Hi Benson,

See if the following schema helps you:

<?xml version="1.0" encoding="UTF-8"?>
<xsd:schema xmlns:xsd="http://www.w3.org/2000/10/XMLSchema"
elementFormDefault="qualified">
  <xsd:element name="Root">
    <xsd:complexType>
      <xsd:sequence>
        <xsd:element name="Group">
          <xsd:complexType>
            <xsd:sequence>
              <xsd:element name="Id">
                <xsd:simpleType>
                  <xsd:restriction base="xsd:string">
                    <xsd:enumeration value="Invoice"/>
                  </xsd:restriction>
                </xsd:simpleType>
              </xsd:element>
              <xsd:element name="value"/>
            </xsd:sequence>
          </xsd:complexType>
        </xsd:element>
        <xsd:choice minOccurs="0" maxOccurs="unbounded">
          <xsd:element name="Group">
            <xsd:complexType>
              <xsd:sequence>
                <xsd:element name="Id"/>
                <xsd:element name="value"/>
              </xsd:sequence>
            </xsd:complexType>
          </xsd:element>
        </xsd:choice>
      </xsd:sequence>
    </xsd:complexType>
  </xsd:element>
</xsd:schema>


Cheers,
Chetan

Benson Cheng wrote:

> Hi,
>
> I hava a schema question.  I need write a schema to validate the following
> sample XML file, the key is that at least one <Group> node is exist, and at
> least one of its <Id> is the "Invoice" value, other <Group>/<Id> could be
> anything.  I think I need use "Choice", but not sure how to do it, any hint
> will be help.
>
> <?xml version="1.0" encoding="UTF-8" ?>
> <Root>
>   <Group>
>      <Id>Invoice</Id>
>      <value>123456</value>
>   </Group>
>   <Group>
>      <Id>Anything1</Id>
>      <value>99999</value>
>   </Group>
>   <Group>
>      <Id>Anything2</Id>
>      <value>888888</value>
>   </Group>
> </Root>
>
> Thanks,
> Benson.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: xerces-j-user-unsubscribe@xml.apache.org
> For additional commands, e-mail: xerces-j-user-help@xml.apache.org

--
Chetan Chudasama
Fujitsu Network Communications
Call: (408) 895 1707
Email: cchetan@nms.fnc.fujitsu.com




---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-j-user-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-j-user-help@xml.apache.org