W3C home > Mailing lists > Public > xmlschema-dev@w3.org > March 2007

RE: xsd:any validation for elements

From: <dmaze@us.ibm.com>
Date: Wed, 7 Mar 2007 10:37:56 -0500
To: "Shlomo Yona" <S.Yona@F5.com>
Cc: xmlschema-dev@w3.org
Message-ID: <OF12C8D6A9.D74A9E2B-ON85257297.00542E95-85257297.0055D73D@lotus.com>
The relevant text in the standard is pretty convoluted; the best thing I 
can point at is the prose in section 3.10.1 of part 1 of the second 
edition.

By way of example, though, against the following schema:

<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
  <xs:element name="root">
    <xs:complexType>
      <xs:any namespace="##any" processContents="skip"/>
    </xs:complexType>
  </xs:element>
</xs:schema>

The following instance is invalid because the "inner" element doesn't 
match its type, even though it's validated against a "skip" wildcard:

<root xmlns:xs="http://www.w3.org/2001/XMLSchema"
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  <inner xsi:type="xs:int">foo</inner>
</root>

If you replaced "foo" with a valid int, the instance would be valid.  If 
you then changed the "skip" in the schema to "strict" it would still be 
valid, even though there's not an element declaration for "inner", because 
the xsi:type attribute names a type to validate against.

My best reading of "Validation Rule: Schema-Validity Assessment (Element)" 
in section 3.3.4 is that, if a strict or lax wildcard (or a normal element 
reference) finds a specific element declaration, then validate against it 
(and xsi:type must be derived from the element's type); otherwise if 
there's an xsi:type attribute, validate against that; otherwise for a skip 
or lax wildcard validate against xs:anyType; otherwise an error.  In 
particular here you're trying to find the [validity] of the element in the 
PSVI, which is in section 3.3.5, and explains that if that algorithm fails 
to find anything and the .context-determined declaration. is mustFind 
(that is, you have a strict wildcard) then the element's [validity] is 
invalid.

David Maze
Engineer, IBM WebSphere DataPower SOA Appliances
One Rogers Street, Cambridge, MA 02142
Phone: 617-693-1306  Fax: 617-693-5541



From:
"Shlomo Yona" <S.Yona@F5.com>
To:
<dmaze@us.ibm.com>
Cc:
<xmlschema-dev@w3.org>
Date:
03/06/2007 11:31 PM
Subject:
RE: xsd:any validation for elements


Hello,
 
Thanks for the reply.
 
Your example with the “strict” option and importing schema does help 
understand, so I think I got the motivation for the “strict” option.
 
I don’t seem to understand the exceptions that you mention with regards to 
xsi:type. Can you please explain, or better yet, point me to the relevant 
text in the standard?
 
Thanks again.
 
Shlomo.
 

From: dmaze@us.ibm.com [mailto:dmaze@us.ibm.com] 
Sent: â 06 îøõ 2007 22:58
To: Shlomo Yona
Cc: xmlschema-dev@w3.org
Subject: Re: xsd:any validation for elements
 

xmlschema-dev-request@w3.org wrote on 03/06/2007 10:56:09 AM:

> I’m not sure that I’m clear about the parsing instructions for 
> xsd:any. Your help in interpretation of the standard is most 
appreciated: 
>   
> The “skip” parser instruction in xsd:any says (I think) – only 
> perform well formedness and namespace checks but don’t try to 
> validate element names and types. 

This isn't quite true.  If the content contains an xsi:type attribute, 
then in all cases the element will be validated against that type.  In the 
"skip" case it's not checked against an element declaration.  But 
otherwise, in the absence of xsi:type, yes, this passes everything through 
without validation. 

> The “lax” parser instruction in xsd:any says (I think) – same as 
> skip but if you encounter an element name that is defined in your 
> schema, then validate it against the schema. 
> The “strict” says (I think) – same as “lax” but if you don’t know 
> the element name – it is a validation error. 

Again, xsi:type matters here: even against a strict wildcard, an element 
without a corresponding global element declaration can still be considered 
valid if it has a valid xsi:type attribute, and the element is valid as 
per the type it declares. 

> The following things make me think that I misinterpret the standard 
correctly: 
> Why use “strict”? you might as well not defined your content group as 
xsd:any. 

It's much easier to specify one xs:any in your schema than a choice of 
dozens (or more!) specific named elements.  If you're importing things 
from other namespaces, you might not even know off hand what all of the 
potential options are.  And if you add global element declarations (or if 
a schema you import adds them) then a strict xs:any will automatically 
pick those up. 

> The “lax” confuses me because I’m not sure if when I encounter <a> I
> should make sure that all its child elements and attributes conform 
> with the schema or just <a> itself with its attributes 

There's no way in XML Schema to cause the validator to look at an 
element's attributes but ignore the content model in the same complex type 
(excepting an xsi:nil in the instance document).  I read the spec as 
requiring a validator to try to validate an element against (1) a matching 
global element declaration, (2) an xsi:type attribute, or failing those 
(3) the same way as a skip wildcard. 

David Maze
Engineer, IBM WebSphere DataPower SOA Appliances
One Rogers Street, Cambridge, MA 02142
Phone: 617-693-1306  Fax: 617-693-5541

Received on Wednesday, 7 March 2007 15:39:24 UTC

This archive was generated by hypermail 2.4.0 : Friday, 17 January 2020 23:15:41 UTC