You are viewing a plain text version of this content. The canonical link for it is here.
Posted to j-users@xalan.apache.org by Brian Hardy <al...@cobaltbloom.com> on 2003/08/23 02:27:25 UTC

namespace declaration lost when passing a nodeset to a java extension function

Hello.

I'm using Xalan 2.4.1 to pass a nodeset to a static Java method that 
requests a parameter of type org.w3c.dom.Node. The nodeset represents a 
complete XML document (at least in theory) that I intend to convert to 
a string to be passed along via JMS for further transformation.

The nodeset contains elements like this:

<xi:include xmlns:xi="http://www.w3.org/2001/XInclude" 
href="/filesystem/path"/>

That are to be eventually parsed and replaced with the contents of the 
xml file in @href. In the Java method, I'm using 
org.apache.xml.serialize.XMLSerializer to convert the nodeset into a 
string like this:

public static void sendXML(org.w3c.dom.Node docNode) {

	orc.w3c.dom.Document doc = (org.w3c.dom.Document)docNode;
	StringWriter stringWriter = new StringWriter();
	XMLSerializer serializer = new XMLSerializer((Writer)stringWriter, new 
OutputFormat(doc));
	try {
		serializer.serialize(doc);
	} catch (IOException ignored) { }
	System.err.println(stringWriter.toString());

}

This works well, except that in the resulting output from 
serialize(doc) the namespace declaration on the xi:include elements is 
missing. This results in invalid XML, which, when parsed after being 
sent via JMS, results in errors stating that the namespace for prefix 
'xi' is undeclared.

I've tried changing the static method's argument type to 
org.w3c.dom.Document and skipping the cast, but Xalan doesn't find the 
method then.

Can anyone tell me either how to avoid losing this namespace 
declaration or another way to pass an entire XML document into an 
extension method?

Thanks a lot.
Brian