Validating XML elements with other XML elements
This should cover W3C XML Schema, Relax NG and DTD related problems.
-
- Posts: 1
- Joined: Tue Mar 13, 2007 2:41 am
- Location: Colorado
Validating XML elements with other XML elements
To whom it may concern,
I have figured out how to validate an element within an XML instance with another element in the same XML instance file. I used keys and keyref and xpath.
How does one validate an XML element in one XML instance file with another XML element in another XML Instance file?
Thanks in advance
I have figured out how to validate an element within an XML instance with another element in the same XML instance file. I used keys and keyref and xpath.
How does one validate an XML element in one XML instance file with another XML element in another XML Instance file?
Thanks in advance
-
- Posts: 4141
- Joined: Fri Mar 28, 2003 2:12 pm
Post by sorin_ristache »
Hello,
You can refer in one XML instance to an element from other XML instance only if the two instances are part of the same XML document, that is one of the two XML instances or both XML instances are included in a master XML instance using XInclude. You must use key and keyref too for referring the element from the other XML instance but the two instances must be included in the same document and this document is validated against the XML Schema which defines the key and keyref. For example the following schema:
can be used to validate the master XML file:
where childID.xml is for example:
and childIDREF.xml is:
Regards,
Sorin
You can refer in one XML instance to an element from other XML instance only if the two instances are part of the same XML document, that is one of the two XML instances or both XML instances are included in a master XML instance using XInclude. You must use key and keyref too for referring the element from the other XML instance but the two instances must be included in the same document and this document is validated against the XML Schema which defines the key and keyref. For example the following schema:
Code: Select all
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="root">
<xs:complexType>
<xs:sequence>
<xs:element name="childID" type="xs:ID"/>
<xs:element name="childIDREF" type="xs:IDREF"/>
</xs:sequence>
</xs:complexType>
<xs:key name="checkChildReference">
<xs:selector xpath="childID"/>
<xs:field xpath="."/>
</xs:key>
<xs:keyref refer="checkChildReference" name="checkRefKeyref">
<xs:selector xpath="childIDREF"/>
<xs:field xpath="."/>
</xs:keyref>
</xs:element>
</xs:schema>
Code: Select all
<root xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="testKeyXInclude.xsd">
<xi:include href="childID.xml" xmlns:xi="http://www.w3.org/2001/XInclude"/>
<xi:include href="childIDREF.xml" xmlns:xi="http://www.w3.org/2001/XInclude"/>
</root>
Code: Select all
<childID>qwerty</childID>
Code: Select all
<childIDREF>qwerty</childIDREF>
Regards,
Sorin
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