Flaw? - <?xml-model?> and multiple namespaces
This should cover W3C XML Schema, Relax NG and DTD related problems.
-
- Posts: 2
- Joined: Mon Sep 02, 2013 10:32 pm
Flaw? - <?xml-model?> and multiple namespaces
Post by Carla Huls »
Hi,
I have two RelaxNG schemas called Address.rng and Customers.rng, with target namespaces "http://www.myserver.com/xmlns/address" and "http://www.myserver.com/xmlns/customers".
Schema Customers.rng has an <anyName> instruction, like this:
This means i can put elements from any namespace except "blah" within element "CustomerInformation", like this:
To validate this document i use an xml-model instruction:
<?xml-model href="Customers.rng" type="application/xml" schematypens="http://relaxng.org/ns/structure/1.0"?>
But, this doesn't work, because namespace "http://www.myserver.com/xmlns/address" is not defined. So, i add a second xml-model instruction:
<?xml-model href="Address.rng" type="application/xml" schematypens="http://relaxng.org/ns/structure/1.0"?>
But, this also doesn't work, because these xml-model instructions are used one-by-one, not together.
Any ideas?
Thank you,
- Carla
Full Example:
Address.rng:
Customers:
Example.xml:
I have two RelaxNG schemas called Address.rng and Customers.rng, with target namespaces "http://www.myserver.com/xmlns/address" and "http://www.myserver.com/xmlns/customers".
Schema Customers.rng has an <anyName> instruction, like this:
Code: Select all
<element name="CustomerInformation">
<anyName>
<except>
<nsName ns="blah"/>
</except>
</anyName>
</element>
Code: Select all
<cust:CustomerInformation xmlns:cust="http://www.myserver.com/xmlns/customers">
<addr:Address xmlns:addr="http://www.myserver.com/xmlns/address">
</addr:Address>
</cust:CustomerInformation>
<?xml-model href="Customers.rng" type="application/xml" schematypens="http://relaxng.org/ns/structure/1.0"?>
But, this doesn't work, because namespace "http://www.myserver.com/xmlns/address" is not defined. So, i add a second xml-model instruction:
<?xml-model href="Address.rng" type="application/xml" schematypens="http://relaxng.org/ns/structure/1.0"?>
But, this also doesn't work, because these xml-model instructions are used one-by-one, not together.
Any ideas?
Thank you,
- Carla
Full Example:
Address.rng:
Code: Select all
<?xml version="1.0" encoding="utf-8"?>
<grammar
datatypeLibrary="http://www.w3.org/2001/XMLSchema-datatypes"
ns="http://www.myserver.com/xmlns/address"
xmlns="http://relaxng.org/ns/structure/1.0"
xmlns:a="http://relaxng.org/ns/compatibility/annotations/1.0">
<start>
<ref name="start"/>
</start>
<define name="start">
<element name="Address">
<element name="Street">
<data type="string"/>
</element>
<element name="City">
<data type="string"/>
</element>
<element name="State">
<data type="string"/>
</element>
<element name="ZipCode">
<data type="string"/>
</element>
</element>
</define>
</grammar>
Code: Select all
<?xml version="1.0" encoding="utf-8"?>
<grammar
datatypeLibrary="http://www.w3.org/2001/XMLSchema-datatypes"
ns="http://www.myserver.com/xmlns/customers"
xmlns="http://relaxng.org/ns/structure/1.0"
xmlns:a="http://relaxng.org/ns/compatibility/annotations/1.0">
<start>
<ref name="start"/>
</start>
<define name="start">
<element name="Customers">
<element name="CustomerInformation">
<element name="CustomerNumber">
<data type="integer"/>
</element>
<element name="blabla">
<data type="integer"/>
</element>
<element>
<anyName>
<except>
<nsName ns="blah"/>
</except>
</anyName>
<text/>
</element>
</element>
</element>
</define>
</grammar>
Code: Select all
<?xml version="1.0" encoding="utf-8"?>
<?xml-model href="Address.rng" type="application/xml" schematypens="http://relaxng.org/ns/structure/1.0"?>
<?xml-model href="Customers.rng" type="application/xml" schematypens="http://relaxng.org/ns/structure/1.0"?>
<cust:Customers
xmlns:addr="http://www.myserver.com/xmlns/address"
xmlns:cust="http://www.myserver.com/xmlns/customers">
<cust:CustomerInformation>
<cust:CustomerNumber error1="">990023</cust:CustomerNumber>
<addr:Address>
<addr:Street>9902 Broadway</addr:Street>
<addr:City>Chicago</addr:City>
<addr:error2/>
<addr:State>IL</addr:State>
<addr:ZipCode error3="">60612</addr:ZipCode>
</addr:Address>
</cust:CustomerInformation>
</cust:Customers>
-
- Posts: 2883
- Joined: Tue May 17, 2005 4:01 pm
Re: Flaw? - <?xml-model?> and multiple namespaces
Hi,
xml-model instructions are meant to associate one or more schemas with the XML document. They are not supposed to be complementary within the same schema model, they are supposed to provide multiple validation steps. This means each xml-model specified schema will be evaluated independently from the others.
http://www.w3.org/TR/xml-model/#the-xml ... nstruction
BTW, is there any reason why you don't refer Address.rng in the Customers.rng schema?
Instead of:
You can use:
In the XML you'll only need the Customers.rng xml-model instruction.
Regards,
Adrian
xml-model instructions are meant to associate one or more schemas with the XML document. They are not supposed to be complementary within the same schema model, they are supposed to provide multiple validation steps. This means each xml-model specified schema will be evaluated independently from the others.
http://www.w3.org/TR/xml-model/#the-xml ... nstruction
BTW, is there any reason why you don't refer Address.rng in the Customers.rng schema?
Instead of:
Code: Select all
<element>
<anyName>
<except>
<nsName ns="blah"/>
</except>
</anyName>
<text/>
</element>
Code: Select all
<externalRef href="Address.rng"/>
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
-
- Posts: 2
- Joined: Mon Sep 02, 2013 10:32 pm
Re: Flaw? - <?xml-model?> and multiple namespaces
Post by Carla Huls »
Thank you for your response.
My question was not of a practical nature. I find it strange that it's not possible to decide in the XML document which namespaces to combine when using the xml-model instruction. In XMLSchema I can do this:
<?xml version="1.0" encoding="utf-8"?>
<cust:Customers
xmlns:addr="http://www.myserver.com/xmlns/address"
xmlns:cust="http://www.myserver.com/xmlns/customers"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="
http://www.myserver.com/xmlns/address Address.xsd
http://www.myserver.com/xmlns/customers Customiers.xsd">
<cust:CustomerInformation>
<cust:CustomerNumber error1="">990023</cust:CustomerNumber>
<addr:Address>
<addr:Street>9902 Broadway</addr:Street>
<addr:City>Chicago</addr:City>
....
When this XML Document is validated, both namespaces (address & customers) are checked.
There is no alternative using xml-model:
<?xml version="1.0" encoding="utf-8"?>
<?xml-model href="Address.rng" type="application/xml" schematypens="http://www.w3.org/2001/XMLSchema"?>
<?xml-model href="Customers.rng" type="application/xml" schematypens="http://www.w3.org/2001/XMLSchema"?>
<cust:Customers
xmlns:addr="http://www.myserver.com/xmlns/address"
xmlns:cust="http://www.myserver.com/xmlns/customers">
<cust:CustomerInformation>
<cust:CustomerNumber error1="">990023</cust:CustomerNumber>
<addr:Address>
<addr:Street>9902 Broadway</addr:Street>
<addr:City>Chicago</addr:City>
....
This is not the same as the previous example: here the XML document is validated twice against both namespaces, one by one.
My question was not of a practical nature. I find it strange that it's not possible to decide in the XML document which namespaces to combine when using the xml-model instruction. In XMLSchema I can do this:
<?xml version="1.0" encoding="utf-8"?>
<cust:Customers
xmlns:addr="http://www.myserver.com/xmlns/address"
xmlns:cust="http://www.myserver.com/xmlns/customers"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="
http://www.myserver.com/xmlns/address Address.xsd
http://www.myserver.com/xmlns/customers Customiers.xsd">
<cust:CustomerInformation>
<cust:CustomerNumber error1="">990023</cust:CustomerNumber>
<addr:Address>
<addr:Street>9902 Broadway</addr:Street>
<addr:City>Chicago</addr:City>
....
When this XML Document is validated, both namespaces (address & customers) are checked.
There is no alternative using xml-model:
<?xml version="1.0" encoding="utf-8"?>
<?xml-model href="Address.rng" type="application/xml" schematypens="http://www.w3.org/2001/XMLSchema"?>
<?xml-model href="Customers.rng" type="application/xml" schematypens="http://www.w3.org/2001/XMLSchema"?>
<cust:Customers
xmlns:addr="http://www.myserver.com/xmlns/address"
xmlns:cust="http://www.myserver.com/xmlns/customers">
<cust:CustomerInformation>
<cust:CustomerNumber error1="">990023</cust:CustomerNumber>
<addr:Address>
<addr:Street>9902 Broadway</addr:Street>
<addr:City>Chicago</addr:City>
....
This is not the same as the previous example: here the XML document is validated twice against both namespaces, one by one.
Jump to
- Oxygen XML Editor/Author/Developer
- ↳ Feature Request
- ↳ Common Problems
- ↳ DITA (Editing and Publishing DITA Content)
- ↳ Artificial Intelligence (AI Positron Assistant add-on)
- ↳ 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