commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ijorge <ijo...@ignos.com>
Subject [JXPATH] Error when create DOM Element without prefix of namespace using createPathAndSetValue()
Date Fri, 11 Feb 2005 08:46:16 GMT
I'm using JXPATH to generate a DOM Element. I have this structure:

<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE Root
    PUBLIC "-//Example//DTD Example/EN"
    "http://www.example.com/example">

<Root
    name="root"
    xmlns="http://www.example.com/example"
    xmlns:exa="http://www.example.com/example">

	<example1 name="aa">
	</example1>

</Root>

I used this jxpath sentence:  context.createPathAndSetValue(
"$root/example1[@name="aa"]/example2", "xx"); where "example2" must have 
the default namespace xmlns="http://www.example.com/example".

But, I received this error:
Factory could not create a child node for path: 
$root/example1[@name='aa']/example2[1]

I tried this other sentence:
context.createPathAndSetValue("$root/example1[@name='aa']/exa:example2", 
"xx"); and this sentence worked correctly.

I have been investigating the source code of JXPATH and I think that the 
error is in org/apache/commons/jxpath/ri/model/dom/DOMNodePointer.java
I have modified this class because, in method createChild(), 
NodeNameTest didn´t have the default namespace when (prefix == null):

Diff between modified class and original class from commons-jxpath-1.2:
397c397,401
<         nodeTest = new NodeNameTest(name);
---
 >         /*
 >          * When new child does not have a prefix, we search the
 >          * default namespace in the ancestors
 >          */
 >          nodeTest = new NodeNameTest(name, getDefaultNamespaceURI());

This change resolves my problem but I don´t know if this behavior is a bug.

---------------------------------------------------------------------
To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-user-help@jakarta.apache.org


Mime
View raw message