Hi all,
I know I'm not the only one to have this problem, and I've seen some people solving this with one single call to setNamespaceAware, but somehow I must be doing something wrong cos it doesn't work for me.
Basically, I want to import namespace'd nodes into a new DOM structure, and I get the usual error:
Exception in thread "main" org.w3c.dom.DOMException: NAMESPACE_ERR: An attempt is made to create or change an object in a way which is incorrect with regard to namespaces.
Here's how I do it: I have a Xindice DB, which I access using the XML:DB API. I then do an XPath query using the XPathQueryService::query function, which returns a ResultSet. My goal is to turn the array of nodes contained in this ResultSet into a single XML structure (org.w3c.dom.Document).
The entries as returned by the call to the query function look like this:
<#document>
<termEntry src:col="/db/test" src:key="entry5" xmlns="http://www.lisa.org/tbx" xmlns:src="http://xml.apache.org/xindice/Query">
<!-- content here... -->
</termEntry>
</#document>
I create a DOM structure as follows:
Node[] result; // the ResultSet returned by the query function is converted into an array of org.w3c.dom.Node's
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
dbf.setNamespaceAware( true );
DocumentBuilder docbuilder = dbf.newDocumentBuilder();
Document doc = docbuilder.newDocument();
Element response = doc.createElement( "termdb-response" );
doc.appendChild( response );
for( int i = 0 ; i < result.length ; i++ ) {
response.appendChild( doc.importNode( result[ i ].getFirstChild(), true ) ); // **** error here ****
}
When this is executed, I get the error named above on the line indicated. As I said, some people seem to have solved the problem by making the DocumentBuilderFactory namespace aware, but I've tried that and it hasn't changed anything. I guess it's very stupid, but could someone please tell me how I can import these nodes into my structure??
Thanks a lot in advance!
pagod