views:

243

answers:

1

I am using Apache Xerces 3.0.1 XInclude. I want to use the xinclude mechanism to include XML files. I have three XML files all in the same directory. test_a.xml xincludes test_b.xml which xincludes test_c.xml. When I just have test_a.xml xinclude test_b.xml, it works. However, when I have test_b.xml xinclude test_c.xml I get the following command line error:

C:\digital_receiver\test>XInclude.exe test_a.xml test_z.xml Parse test_a.xml in progress ... Fatal Error at file C:\digital_receiver\test/test_a.xml, line 3, char 34 Message: no scheme found in URI finished.

test_a.xml:

<?xml version="1.0" encoding="ISO-8859-1"?>
<test_a xmlns:xi="http://www.w3.org/2001/XInclude"&gt;
  <xi:include href="test_b.xml"/>
</test_a>

test_b.xml:

<?xml version="1.0" encoding="ISO-8859-1"?>
<test_b xmlns:xi="http://www.w3.org/2001/XInclude"&gt;
  <ch>5</ch>
  <xi:include href="test_c.xml"/>
</test_b>

test_c:xml:

<?xml version="1.0" encoding="ISO-8859-1"?>
<test_c>
  <channel>1</channel>
</test_c>

Any help would be appreciated.

A: 

As far as I can tell, your XML is OK, but I wouldn't claim to be the last word on this.

It's my guess that you're hitting a bug in Xerces' XInclude processing. I note that while this code is almost three years old, it apparently wasn't released until Xerces 3.0, so it may be relatively untested. (And given the way that base URIs of included documents are handled in XInclude, the possibility of a bug here seems like it's greater than 0.)

As a workaround, I'd suggest doing what the error message suggests: add a scheme to the URIs for the included files. Unfortunately, for file URIs, that also means you need to use an absolute URI.

test_a.xml:

<?xml version="1.0" encoding="ISO-8859-1"?>
<test_a xmlns:xi="http://www.w3.org/2001/XInclude"&gt;
  <xi:include href="file://path/to/directory/test_b.xml"/>
</test_a>

test_b.xml:

<?xml version="1.0" encoding="ISO-8859-1"?>
<test_b xmlns:xi="http://www.w3.org/2001/XInclude"&gt;
  <ch>5</ch>
  <xi:include href="file://path/to/directory/test_c.xml"/>
</test_b>

UPDATE: There is indeed a similar bug at apache.org. (I think it's describing the same issue, but the wording on the report makes it sound like even a single layer of inclusion would fail when using relative paths.)

Dan Breslau
Thanks Dan. I am able to get a single layer of inclusion to function properly. I guess I can wait until they fix the bug.
szielenski