Qualifying global elements
Questions about XML that are not covered by the other forums should go here.
-
- Posts: 11
- Joined: Thu Nov 21, 2013 3:34 pm
Qualifying global elements
Hello,
I have a question about qualifying elements in the instance that are globally declared in the schema.
I have the two following schemas:
and
When I create an instance based on Main.xsd schema, using element C as a child of element A (replacing the ##any placeholder), it is valid in Oxygen (and other tools for that matter) with or without the namespace prefix used for element C:
And this is valid as well:
Can you explain why? I always knew that if an element is declared globally in the schema and the namespace is explicit, it has to be qualified in the instance. Why then the <C> without namespace prefix is valid? I’m clearly missing something here.
Thank you for any help,
Ewa
I have a question about qualifying elements in the instance that are globally declared in the schema.
I have the two following schemas:
Code: Select all
<xs:schema xmlns:L="HKJ" xmlns:xs="http://www.w3.org/2001/XMLSchema" targetNamespace="HKJ" elementFormDefault="unqualified" attributeFormDefault="unqualified">
<xs:element name="Root">
<xs:complexType>
<xs:sequence>
<xs:element name="A">
<xs:complexType>
<xs:sequence>
<xs:any namespace="##any" processContents="lax" minOccurs="0" maxOccurs="unbounded"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="B" type="xs:string"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
Code: Select all
<xs:schema xmlns:G="XYZ" xmlns:xs="http://www.w3.org/2001/XMLSchema" targetNamespace="XYZ" elementFormDefault="unqualified" attributeFormDefault="unqualified">
<xs:element name="C">
<xs:complexType>
<xs:sequence>
<xs:element name="D"/>
<xs:element name="E"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
Code: Select all
<L:Root xmlns:L="HKJ" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="HKJ Main.xsd">
<A>
<G:C xmlns:G="XYZ" xsi:schemaLocation="XYZ Component.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<D/>
<E/>
</G:C>
</A>
<B>String</B>
</L:Root>
Code: Select all
<L:Root xmlns:L="HKJ" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="HKJ Main.xsd">
<A>
<C xmlns:G="XYZ" xsi:schemaLocation="XYZ Component.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<D/>
<E/>
</C>
</A>
<B>String</B>
</L:Root>
Thank you for any help,
Ewa
-
- Posts: 2879
- Joined: Tue May 17, 2005 4:01 pm
Re: Qualifying global elements
Hello,
The problem is that the schema allows any element from any namespace within the A element, even if a schema is not available for it. This happens because of processContents="lax":
This can be easily fixed by making processContents="strict". You'll then see the results you are expecting, instance 1 validates and instance 2 fails.
Regards,
Adrian
That is correct, globally declared elements are always qualified (in the target namespace).Iwicka wrote: I always knew that if an element is declared globally in the schema and the namespace is explicit, it has to be qualified in the instance. Why then the <C> without namespace prefix is valid? I’m clearly missing something here.
The problem is that the schema allows any element from any namespace within the A element, even if a schema is not available for it. This happens because of processContents="lax":
Code: Select all
<xs:any namespace="##any" processContents="lax" minOccurs="0" maxOccurs="unbounded"/>
e.g. This "validates perfectly" and doesn't have anything to do with the Component schema. So, "anything goes":About processContents wrote:Specifies the validation constraint to be applied on the content that matched the wildcard. Possible values are
* skip - that means no validation
* lax - that means validation will be performed if a schema is available
* strict - that means validation is required
The default is strict.
Code: Select all
<L:Root xmlns:L="HKJ" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="HKJ Main.xsd">
<A>
<ANYTHING>
<I/>
<WANT/>
</ANYTHING>
</A>
<B>String</B>
</L:Root>
Regards,
Adrian
Adrian Buza
<oXygen/> XML Editor, Schema Editor and XSLT Editor/Debugger
http://www.oxygenxml.com
<oXygen/> XML Editor, Schema Editor and XSLT Editor/Debugger
http://www.oxygenxml.com
Return to “General XML Questions”
Jump to
- Oxygen XML Editor/Author/Developer
- ↳ Feature Request
- ↳ Common Problems
- ↳ DITA (Editing and Publishing DITA Content)
- ↳ SDK-API, Frameworks - Document Types
- ↳ DocBook
- ↳ TEI
- ↳ XHTML
- ↳ Other Issues
- Oxygen XML Web Author
- ↳ Feature Request
- ↳ Common Problems
- Oxygen Content Fusion
- ↳ Feature Request
- ↳ Common Problems
- Oxygen JSON Editor
- ↳ Feature Request
- ↳ Common Problems
- Oxygen PDF Chemistry
- ↳ Feature Request
- ↳ Common Problems
- Oxygen Feedback
- ↳ Feature Request
- ↳ Common Problems
- Oxygen XML WebHelp
- ↳ Feature Request
- ↳ Common Problems
- XML
- ↳ General XML Questions
- ↳ XSLT and FOP
- ↳ XML Schemas
- ↳ XQuery
- NVDL
- ↳ General NVDL Issues
- ↳ oNVDL Related Issues
- XML Services Market
- ↳ Offer a Service