Skip to Content.
Sympa Menu

xom-interest - [XOM-interest] XOM - CatalogResolver - XInclude - namespaces

xom-interest AT lists.ibiblio.org

Subject: XOM API for Processing XML with Java

List archive

Chronological Thread  
  • From: Luke Weese <lweese AT gmail.com>
  • To: xom-interest AT lists.ibiblio.org
  • Subject: [XOM-interest] XOM - CatalogResolver - XInclude - namespaces
  • Date: Fri, 13 May 2005 14:46:39 -0500

Hello all, first I want to say I think XOM is wonderful and so easy to
use, thank you for a great API Mr Harold.

I have put together a help system based on Docbook XML, with a couple
of nasty requirements that are causing me trouble. These are XML
catalogs and XInclude support. I have had this working with libxml's
xmllint utility, but the need has arisen for a Java-based replacement.
XOM seems to be the only java API that supports XInclude with the
XPointer attribute, but alas, catalogs are not supported. I have
searched the list and found some instructions on using Apache's (Norm
Walsh's) ResolvingXMLReader to plug in catalog support, but I am
getting errors I do not understand.

First, I'll explain my need for catalog support and how it relates to
XInclude. This is a sample line from an XML document:

<xi:include xmlns:xi="http://www.w3.org/2001/XInclude";
href="file:///fw/generic/genericText.xml"
xpointer="genericText_editKeyField" >

As you can see, the "href" attribute is not a valid url. With xmllint,
I used an XML catalog to rewrite the URI to a local file, like this:

<rewriteURI
uriStartString="file:///fw/"
rewritePrefix="file:///home/pulse/core/help/" />

Using xmllint, this would create an href of
"file:///home/pulse/core/help/generic/genericText.xml", which is
correct. So, here is my java code that attempts to force XOM to use
the ResolvingXMLReader as the parser:

// srcFile is the XML file
System.setProperty("xml.catalog.files",
"/home/pulse/core/help/catalog.xml");
XMLReader parser = new org.apache.xml.resolver.tools.ResolvingXMLReader();
nu.xom.Builder builder = new nu.xom.Builder(parser);
nu.xom.Document input = builder.build(srcFile.getAbsolutePath());

builder.build throws a ParserException with the following message:
-- nu.xom.ParsingException: Additional namespace
http://www.w3.org/2001/XInclude conflicts with existing namespace
binding. at line -1, column -1.

This has me totally baffled. I get no error when creating the Builder
with no specified parser, but of course my Xincludes arent resolved as
the URI's are invalid. Its very possible I'm misunderstanding some
basic knowledge of XML parsing; it is a very grey area for me. So
please be explicit in any explanations.

Thanks so much!
Luke Weese




Archive powered by MHonArc 2.6.24.

Top of Page