W3C home > Mailing lists > Public > xmlschema-dev@w3.org > February 2002

RE: Limited implementation of Global Attributes?

From: Lehmann, Steen <slehmann@silverstream.com>
Date: Fri, 22 Feb 2002 10:00:06 +0100
Message-ID: <FD8A740186525243807FBCDB7E739D0585F2CE@EXBE1.silverstream.be>
To: "'ptomlinson@atmedicausa.com'" <ptomlinson@atmedicausa.com>
Cc: xmlschema-dev@w3.org

xmlns:Action="Add" declares a new local namespace prefix called Action with
the URI "Add" which is not what you want.

The problem with your schema is that the Action attribute is globally
declared, thus requiring it to be explicitly assigned to a namespace. Since
your instance document uses a default namespace instead of declaring a
prefix and using that, the attributes in it are NOT in that namespace (which
is probably a little known fact about XML and namespaces).

If you want to use Action without an explicit namespace qualifier, declare
it in a global attributeGroup in the schema (so that the attribute
declaration itself is no longer global).

Hope this helps,

-- Steen

> -----Original Message-----
> From: Paul Tomlinson [mailto:ptomlinson@atmedicausa.com] 
> Sent: 21. februar 2002 22:14
> To: xmlschema-dev@w3.org
> Subject: Limited implementation of Global Attributes?
> 
> 
> I'm encountering a rather unique error that may have to do 
> with the actual schema specification (verified with separate 
> parsing engines) I'd like to get someone else's eyes on.  
> Take the following snippet of XML:
> 
> ---------
> <TopLevelElement
>   xmlns="http://someurl.com/namespace/data/1.0"
>   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
>   
> xsi:schemaLocation="http://someurl.com/namespace/data/1.0/this
> Form.xsd">
> 
>   <SecondLevelElement xmlns:Action="Add">
>     ...
>   </SecondLevelElement>
> </TopLevelElement>
> ---------
> 
> Note the "xmlns:" namespace qualifier in front of "Action", 
> basically declaring this attribute to exist in the currently 
> defined space.  I
> *should* be able to take this off and simply have:
> 
> <SecondLevelElement Action="Add">
> 
> But no such luck - this produces an error, varying in text 
> from one implementation to the next, but identical in trigger:
> 
> XMLSpy: This file is not valid: Unexpected attribute 'Action' 
> - the parent element requires some attributes to be 
> qualified, because your Schema uses attributeForm='qualified' 
> or global attributes.  You may need to specify a prefix for 
> your schema namespace.
> 
> MSXML4: Validate failed because the document does not contain 
> exactly one root node.
> 
> XMLSpy makes a great deal more sense, but still doesn't quite 
> explain the situation.  The "Action" attribute *is* a global 
> definition, but it's been incorporated into the current 
> namespace.  The main schema is similar to
> this:
> ---------
> <xs:schema
>   xmlns="http://someurl.com/namespace/data/1.0"
>   targetNamespace="http://someurl.com/namespace/data/1.0"
>   xmlns:xs="http://www.w3.org/2001/XMLSchema"
>   elementFormDefault="qualified"
>   attributeFormDefault="unqualified">
> 
>   <xs:include schemaLocation="GenericTypes.xsd"/>
>   <xs:element name="TopLevelElement">
>     <xs:complexType>
>       <xs:sequence>
>           ...
>         <xs:element name="SecondLevelElement" maxOccurs="unbounded">
>           <xs:complexType>
>             <xs:complexContent>
>               <xs:extension base="SecondLevelType">
>                 <xs:attribute ref="Action"/>
>               </xs:extension>
>             </xs:complexContent>
>           </xs:complexType>
>         </xs:element>
>           ...
>       </xs:sequence>
>     </complexType>
>   </xs:element>
> </xs:schema>
> ---------
> Referencing a second schema with global elements 
> (GenericTypes.xsd) and attributes, thus:
> ---------
> <xs:schema
>   xmlns="http://someurl.com/namespace/data/1.0"
>   xmlns:xs="http://www.w3.org/2001/XMLSchema"
>   targetNamespace="http://someurl.com/namespace/data/1.0"
>   elementFormDefault="qualified"
>   attributeFormDefault="unqualified">
> 
>   <xs:attribute name="Action">
>     <xs:simpleType>
>       <xs:restriction base="xs:string">
>         <xs:enumeration value="Add"/>
>         <xs:enumeration value="Update"/>
>         <xs:enumeration value="Delete"/>
>         <xs:enumeration value="NoChange"/>
>       </xs:restriction>
>     </xs:simpleType>
>   </xs:attribute>
> </xs:schema>
> ---------
> 
> It's probably important to note that although I have 
> definitions scattered across multiple documents (all within 
> the same namespace) the same error is encountered even if the 
> "Action" attribute definition is removed to the primary 
> validating schema. The schemata are valid and interact with 
> one another properly (referenced definitions from 
> GenericTypes in the primary schema are properly enforced, 
> etc.).  No issue occurs in validating these - only when the 
> XML enters the picture.  Apparently the attribute being 
> global invalidates the schema's attributeFormDefault, but 
> that still shouldn't push the responsibility of declaring 
> namespace qualifications onto the XML.  Aside from declaring 
> "Action" locally for those elements which require it (or 
> constructing a verbose schema via XSL which references a 
> single implementation, for ease of
> maintenance) is there any way to clean this up?  Has anyone 
> encountered this before that might be able to help me 
> understand the reasoning in force?
> 
> Paul L. Tomlinson
> ptomlinson@atmedicausa.com
> 
> 
Received on Friday, 22 February 2002 04:05:28 GMT

This archive was generated by hypermail 2.2.0+W3C-0.50 : Tuesday, 11 January 2011 00:14:27 GMT