Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1012351
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T09:55:59+00:00 2026-05-16T09:55:59+00:00

When upgrading from libxml2 2.6 to 2.7, some behavior changed for me. I’ve located

  • 0

When upgrading from libxml2 2.6 to 2.7, some behavior changed for me. I’ve located the bug report on their site that regards this change, its https://bugzilla.gnome.org/show_bug.cgi?id=571271 .

Interestingly, they report that “and I guess we misinterpreted the expected behaviour of this options
(though I’m still not 100% sure)” – they weren’t sure if they were reading the spec correctly yet they committed the fix.

I think the previous behavior is correct, so I wanted to see if anyone here has knowledge in either direction.

Basically, does <xs:all>elem1, elem2, ..<xs:all> mean that “all or none of elem1, elem2.. must be present”, or “any of elem1, elem2 .. may be present” ? Even though it seems like the former, two sources don’t make this clear:

http://www.w3.org/TR/xmlschema-0/#ref18 – “All the elements in the group may appear once or not at all, and they may appear in any order.”

http://www.w3schools.com/Schema/el_all.asp – “The example above indicates that the “firstname” and the “lastname” elements can appear in any order and each element CAN appear zero or one time!”

The script below, using lxml, reports success when using libxml2 2.6, but the second schema validation fails on 2.7. Can someone confirm if 2.7 is doing the right or the wrong thing here ?

from lxml import etree
from StringIO import StringIO

schema = """
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
 <xs:element type="parent-type" name="parent"/>
 <xs:complexType name="parent-type">
   <xs:all maxOccurs="1" minOccurs="0">
     <xs:element type="xs:int" name="int-attr"/>
     <xs:element type="xs:string" name="str-attr"/>
   </xs:all>
 </xs:complexType>
</xs:schema>
"""

xmlschema = etree.XMLSchema(etree.parse(StringIO(schema)))

# passes
doc1 = """
<parent xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="http://www.example.com/xml/schemas">
 <str-attr>some value</str-attr>
 <int-attr>12</int-attr>
</parent>
"""

# fails.  it wants both "int-attr" and "str-attr" to be present.
# didn't think this was how "xs:all" worked ?
doc2 = """
<parent xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="http://www.example.com/xml/schemas">
 <int-attr>12</int-attr>
</parent>
"""

for i, doc in enumerate((doc1, doc2, )):
   doc = etree.parse(StringIO(doc))
   try:
       xmlschema.assertValid(doc)
       print "document %d is valid." % i
   except Exception, e:
       print "document %d is not valid." % i
       print e

output:

document 0 is valid.
document 1 is not valid.
Element 'parent': Missing child element(s). Expected is ( str-attr )., line 2
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T09:56:00+00:00Added an answer on May 16, 2026 at 9:56 am

    User Jörn Horstmann actually already answered your question correctly but the formatting could make the answer seem a bit unclear. I hope these examples helps those that were left puzzled.

    What do minOccurs and maxOccurs mean on <xs:all> element

    Remember that <xs:all> and <xs:element> have default value “1” for minOccurs and maxOccurs. Therefore

    <xs:all>
      <xs:element type="xs:int" name="int-attr"/>
      <xs:element type="xs:string" name="str-attr"/>
    </xs:all>
    

    Is in fact the same as

    <xs:all minOccurs="1" maxOccurs="1">
      <xs:element type="xs:int" name="int-attr" minOccurs="1" maxOccurs="1"/>
      <xs:element type="xs:string" name="str-attr" minOccurs="1" maxOccurs="1"/>
    </xs:all>
    

    This means that the whole <xs:all> group is mandatory as well as both of the elements defined in it – the order is free. Thus XML document

    <parent xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
            xsi:noNamespaceSchemaLocation="http://www.example.com/xml/schemas">
      <int-attr>12</int-attr>
    </parent>
    

    would be invalid. Using attribute minOccurs="0" on <xs:all> means that the whole group is optional and in this case it would allow also an empty <parent/> element. I see that this is what the spec really means with “All the elements in the group may appear once or not at all”. I am not a native English speaker but I would also say that the second example on the w3schools page is incorrect. It should read “both elements CAN appear zero or one time” instead of “each element CAN appear zero or one time”.

    maxOccurs attribute of <xs:all> is fixed to value “1”.

    How to define a tag that has zero or one of each child tag

    So this is what you asked in your comment and what you tried to validate in the first place. Optional elements inside <xs:all> group are achieved by adding attribute minOccurs="0" on those elements. Example below

    <xs:all minOccurs="1" maxOccurs="1">
      <xs:element type="xs:int" name="int-attr" minOccurs="0" maxOccurs="1"/>
      <xs:element type="xs:string" name="str-attr" minOccurs="0" maxOccurs="1"/>
    </xs:all>
    

    This schema would validate XML document

    <parent xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
            xsi:noNamespaceSchemaLocation="http://www.example.com/xml/schemas">
      <int-attr>12</int-attr>
    </parent>
    

    Since both of the elements are optional (because they have minOccurs="0") this definition also allows an empty <parent/> element. Although the cardinality restriction on elements in a way “overrides” the one set on <xs:all> the spec also says: “no element in the content model may appear more than once, i.e. the permissible values of minOccurs and maxOccurs are 0 and 1”. So you can’t have a group that has same elements multiple times in random order, or at least you can’t use <xs:all> to create such type.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an app that I'm upgrading from some beta bits - and my
Upgrading from ASP.NET WebAPI Beta to RC has provided some amount of excitement and
I noticed after upgrading from 4.2 to 4.3.1 that there is no longer a
I am upgrading from the old SecureWebPages that automates the switching between Http and
I have a hairy set of routes that I'm upgrading from Rails 2 to
I'm upgrading from ColdFusion 8 to ColdFusion 9. I have a Java class that
After upgrading from Firefox 3.6 to FF4 i was surprised to see that jQuery
I'm upgrading from 3.1 to 3.2. Other than looking at 3.1's site-packages directory to
I'm upgrading from Delphi 2005 to Delphi 2010. I'm having this problem : the
I found this after upgrading from Oracle 11g Release 1 to Release 2. The

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.