You are viewing a plain text version of this content. The canonical link for it is here.
Posted to xindice-users@xml.apache.org by Geoffrey Shuetrim <ge...@galexy.net> on 2005/06/21 11:01:50 UTC
Problems with setContentAsDOM if the DOM uses namespaces
I am using the setContentAsDOM method provided by XMLResource instances
to specify the content that I wish to insert into an Xindice database
but am running into problems if the DOM object that is provided as an
argument has had nodes created using the createElementNS or
setAttributeNS methods.
The attached source code provides two JUnit tests. One works because it
does not have namespace declarations for the nodes in the document. The
other fails because it does. The tests assume that the database URI is:
xmldb:xindice://localhost:8180/db
The problem occurs at the point where the database manager attempts to
insert the XMLResource into the relevant collection, complaining about
difficulties parsing the document.
My environment is as follows:
OS: Debian testing
Container: tomcat 4
Xindice: 1.1b4
Any insights into what is going wrong would be very much appreciated.
Regards
Geoff Shuetrim
Re: Running the JUnit tests for Xindice
Posted by Todd Byrne <by...@cns.montana.edu>.
Also in build.properties there is a line
test.xmlrpc.hostport=localhost:8080
Just change it to point to the port that a xindice server is running.
Todd
Vadim Gritsenko wrote:
> Geoffrey Shuetrim wrote:
>
>> I am trying to test a patch to TextWriter.java but am running into some
>> problems with running the JUnit tests.
>>
>> Specifically, all tests that rely on AbstractXMLDbClient seem to be
>> falling over with a null pointer exception. This is because the client
>> field of that class is never being initialised.
>>
>> Is there something I should be sorting out in my configuration of the
>> Xindice source to avoid this problem?
>
>
> Following sequence works for me:
>
> svn up
> rm -rf build
> ./build.sh
> ./xindice.sh [in second window]
> ./build.sh test
>
> Results are in build/test-report/index.html or some such.
>
> Vadim
Re: Running the JUnit tests for Xindice
Posted by Vadim Gritsenko <va...@reverycodes.com>.
Geoffrey Shuetrim wrote:
> I am trying to test a patch to TextWriter.java but am running into some
> problems with running the JUnit tests.
>
> Specifically, all tests that rely on AbstractXMLDbClient seem to be
> falling over with a null pointer exception. This is because the client
> field of that class is never being initialised.
>
> Is there something I should be sorting out in my configuration of the
> Xindice source to avoid this problem?
Following sequence works for me:
svn up
rm -rf build
./build.sh
./xindice.sh [in second window]
./build.sh test
Results are in build/test-report/index.html or some such.
Vadim
Running the JUnit tests for Xindice
Posted by Geoffrey Shuetrim <ge...@galexy.net>.
I am trying to test a patch to TextWriter.java but am running into some
problems with running the JUnit tests.
Specifically, all tests that rely on AbstractXMLDbClient seem to be
falling over with a null pointer exception. This is because the client
field of that class is never being initialised.
Is there something I should be sorting out in my configuration of the
Xindice source to avoid this problem?
Regards
Geoff Shuetrim
Re: Problems with setContentAsDOM if the DOM uses namespaces
Posted by Geoffrey Shuetrim <ge...@galexy.net>.
Looking further into this problem, this issue arises from the way that
the setContentAsDOM method serialises the DOM node to obtain a text
string. That serialisation is done with the TextWriter class, which
seems to be a roll-your-own serialisation class that largely ignores
namespace declarations in the serialisation process. This means that
when the string needs to be parsed as XML, it is not valid XML.
I can get around this easily enough by using the Xerces XML serialiser
as per the method below.
/**
* Convert a DOM object to a string.
* @param dom The DOM object to convert to a string.
* @return The string that is the serialised content of the DOM
object.
* @throws XBRLException if an IO exception occurs.
*/
private String DOM2String(Document node) throws XBRLException {
try {
StringWriter sw = new StringWriter();
org.apache.xml.serialize.OutputFormat format = new
org.apache.xml.serialize.OutputFormat("xml", "UTF-8", true);
org.apache.xml.serialize.XMLSerializer output = new
org.apache.xml.serialize.XMLSerializer(sw, format);
output.setNamespaces(true);
output.serialize(node);
sw.flush();
String out = sw.toString();
sw.close();
return out;
} catch (IOException e) {
...
}
}
This seems to handle all of the namespace issues nicely enough (though I
have not tested passing in any DOM node rather than passing in a
Document node), leaving open the question: why not use this (or the
Xalan 2.7 serialiser when it is released next month [the 2.6 Xalan
serialiser has some namespace issues of its own]) instead of using the
TextWriter class?
Cheers
Geoff Shuetrim
On Tue, 2005-06-21 at 19:01 +1000, Geoffrey Shuetrim wrote:
> I am using the setContentAsDOM method provided by XMLResource instances
> to specify the content that I wish to insert into an Xindice database
> but am running into problems if the DOM object that is provided as an
> argument has had nodes created using the createElementNS or
> setAttributeNS methods.
>
> The attached source code provides two JUnit tests. One works because it
> does not have namespace declarations for the nodes in the document. The
> other fails because it does. The tests assume that the database URI is:
> xmldb:xindice://localhost:8180/db
>
> The problem occurs at the point where the database manager attempts to
> insert the XMLResource into the relevant collection, complaining about
> difficulties parsing the document.
>
> My environment is as follows:
>
> OS: Debian testing
> Container: tomcat 4
> Xindice: 1.1b4
>
> Any insights into what is going wrong would be very much appreciated.
>
> Regards
>
> Geoff Shuetrim
>