RelaxNG and XInclude not validating correctly

This should cover W3C XML Schema, Relax NG and DTD related problems.
avaspell
Posts: 2
Joined: Tue Jul 15, 2008 9:09 pm

RelaxNG and XInclude not validating correctly

Post by avaspell »

I have a document that I'm validating against a RelaxNG schema, and whenever I have a document that uses an XInclude to reference another entity, the validation fails complaining that the element that I'm referencing is not allowed in this context. However, if I paste the element inline and remove the XInclude, it validates just fine. I have XInclude processing turned on. Here's a snippet of the XML I'm dealing with:


Base XML:

Code: Select all

<profile xmlns="http://www.suse.com/1.0/yast2ns" xmlns:config="http://www.suse.com/1.0/configns"
xmlns:xinclude="http://www.w3.org/2001/XInclude">
<configure>
<files config:type="list">
<file id="file">
<xinclude:include
href="http://www.example.com/file.xml"/>
<file_path>/tmp/file</file_path>
</file>
</files>
</configure>
</profile>
And the XIncluded document looks like this:

Code: Select all

<?xml version="1.0"?>
<file_contents><![CDATA[File Data
]]>
</file_contents>
The editor shows the error in the XIncluded file and shows the file_contents element, so it's getting the resource, just won't validate it. Does the RelaxNG schema have to have something special in it to allow XIncludes?

Thanks!
avaspell
Posts: 2
Joined: Tue Jul 15, 2008 9:09 pm

Re: RelaxNG and XInclude not validating correctly

Post by avaspell »

I figured it out. When the parser includes the referenced document, it uses the namespace in the included document, not the parent. Since I was defining a namespace in the parent, but not in the child, the parser was inserting a namespace declaration of "", and so the RelaxNG schema was properly rejecting the element. Declaring the namespace in the included document produced the dsired results.
george
Site Admin
Posts: 2095
Joined: Thu Jan 09, 2003 2:58 pm

Re: RelaxNG and XInclude not validating correctly

Post by george »

Hi,

Great to see that you managed to solve the problem.
It is always useful to get the document with the XInclude resolved to see what actually goes to the validation engine. To obtain that in oXygen just pass the document through an identity XSLT transformation, that is a stylesheet like

Code: Select all


<?xml version="1.0"?> 
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:template match="node() | @*">
<xsl:copy>
<xsl:apply-templates select="node() | @*"/>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>
or

Code: Select all


<?xml version="1.0"?> 
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:template match="/">
<xsl:copy-of select="."/>
</xsl:template>
</xsl:stylesheet>
Best Regards,
George
George Cristian Bina
Post Reply