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

Post by shand1234 » Sat Oct 20, 2007 2:27 am

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

Posts: 4144
Joined: Fri Mar 28, 2003 2:12 pm

Post by sorin_ristache » Mon Oct 22, 2007 12:12 pm


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="">
<xs:element name="root">
<xs:element name="childID" type="xs:ID"/>
<xs:element name="childIDREF" type="xs:IDREF"/>
<xs:key name="checkChildReference">
<xs:selector xpath="childID"/>
<xs:field xpath="."/>
<xs:keyref refer="checkChildReference" name="checkRefKeyref">
<xs:selector xpath="childIDREF"/>
<xs:field xpath="."/>
can be used to validate the master XML file:

Code: Select all

<root xmlns:xsi=""
<xi:include href="childID.xml" xmlns:xi=""/>
<xi:include href="childIDREF.xml" xmlns:xi=""/>
where childID.xml is for example:

Code: Select all

and childIDREF.xml is:

Code: Select all



Post Reply