logo       


Choosing A Webhost:
A web hosting service is a type of Internet hosting service that allows individuals and organizations to provide their own website accessible via the World Wide Web. Web hosts are companies that provide space on a server they own for use by their clients as well as providing Internet connectivity, typically in a data center. Web hosts can also provide data center space and connectivity to the Internet for servers they do not own to be located in their data center, called colocation. more...

Validation of XML Schema (XSD) element groups: msg#00029

Subject: Validation of XML Schema (XSD) element groups
I have searched the mailing list archives (user and dev) and checked
Jira but I cannot find anything that exactly matches this potential
problem (most if not all of the issues are with the combination of
"group" with "choice"). This may mean that I am misunderstanding the XSD
spec. but I am sure that someone will let me know if that is the case!

I am trying to create a schema definition for an element that must
contain either or both of two sub-elements. I do not want to make both
sub-elements optional because I want to ensure that users send at least
one of them but I cannot use "choice" because I want users to be able to
send both elements if necessary. I thought that element groups might be
the answer and so this is the schema I created (test_group.xsd):

<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema";>

  <xsd:element name="root">
    <xsd:complexType>
      <xsd:sequence>
        <xsd:element ref="elements" minOccurs="1"
maxOccurs="unbounded"/>
      </xsd:sequence>
    </xsd:complexType>
  </xsd:element>

  <xsd:element name="elements">
    <xsd:complexType>
      <xsd:sequence>
        <xsd:element name="element1" type="xsd:string" minOccurs="1"
maxOccurs="1"/>
        <xsd:group   ref="element_group"               minOccurs="1"
maxOccurs="1"/>
      </xsd:sequence>
    </xsd:complexType>
  </xsd:element>

  <xsd:group name="element_group">
    <xsd:sequence>
      <xsd:element name="element2" type="xsd:string" minOccurs="0"
maxOccurs="1"/>
      <xsd:element name="element3" type="xsd:string" minOccurs="0"
maxOccurs="1"/>
    </xsd:sequence>
  </xsd:group>

</xsd:schema>

Note that both elements within the group are optional but the group is
specified as mandatory within the definition of "elements" (minOccurs =
1). This is the test data:

<?xml version="1.0"?>
<root xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";
      xsi:noNamespaceSchemaLocation="test_group.xsd">
  <elements>
    <element1>aaaa</element1>
  </elements>
  <elements>
    <element1>aaaa</element1>
    <element2>bbbb</element2>
  </elements>
  <elements>
    <element1>aaaa</element1>
    <element3>cccc</element3>
  </elements>
  <elements>
    <element1>aaaa</element1>
    <element2>bbbb</element2>
    <element3>cccc</element3>
  </elements>
</root>

I expected the first occurrence of "<elements>" to fail (neither
<element2> nor <element3> is present) but the file passed validation. Is
it Xerces-J (2.8.0), the schema or my understanding that is incorrect
and, if it is not the Xerces-J, is there a way to do what I want in a
W3C schema?

Note: Validation against a DTD showed the same problem.

Thanks,
Andrew

All opinions are completely my own - after all, who else would want to
take credit for them?


Ruby Jobs
Java Jobs
Jobs in California
more...
what
job title, keywords
where
city, state, zip
jobs by job search
<Prev in Thread] Current Thread [Next in Thread>
Google Custom Search

Recently Viewed:
encryption.gpg....    ietf.rfc822/199...    freebsd.devel.i...    lang.haskell.li...    mail.squirrelma...    web.zope.plone....    yellowdog.gener...    text.xml.xalan....    recreation.phot...    kde.devel.educa...    hardware.bus.ca...    printing.ghosts...    voip.peering/20...    assembly/2006-0...    org.user-groups...    culture.interne...    network.i2p/200...    boot-loaders.ya...    xfree86.render/...    qnx.openqnx.dev...    jakarta.velocit...    user-groups.pal...   
Home | blog view | USPTO Patent Archive | advertise | OSDir is an inevitable website. super tiny logo

Free Magazines

Cisco News
Receive a free quarterly e-newsletter with exclusive articles on how Cisco IT uses its own products and solutions to enable the business.
subscribe

Systems Management News, the newspaper for IT systems administration and data center managers! Each issue of Systems Management News is chock-full of news and analysis to help you understand what's happening in your field.
subscribe

The Enterprise Newsweekly eWeek is the essential technology information source for builders of e-business.
subscribe

Oracle Magazine Oracle Magazine contains technology strategy articles, sample code, tips, Oracle and partner news, how to articles for developers and DBAs, and more. Oracle (NASDAQ: ORCL) is the world's largest enterprise software company.
subscribe

Total Telecom Total Telecom is "The Economist of the communications industry".
subscribe