Hello,
I am struggling with what seems to be a bug in the AXIOM API. There appears
to be no way to declare a default namespace in the parent node, and have
this propagate down to the child elements. In other words, I am trying to
declare a default namespace in the parent node, and have the child nodes
automatically belong to that namespace. I created a JIRA more than 2 months
ago, but it still seems like nobody even looked at it. I also tried
emailing Apache, but I get no response. Here is the original JIRA
submission. Any help would be appreciated!
Key: AXIS2-3156
URL: https://issues.apache.org/jira/browse/AXIS2-3156
Project: Axis 2.0 (Axis2)
Issue Type: Bug
Components: om
Affects Versions: 1.3
Environment: Microsoft Windows 2003 Server, Java 1.5.0_11. Axis2
version 1.3 (uses AXIOM version 1.2.5).
Reporter: Yechiel Mondrowitz
Fix For: 1.3
When calling declareDefaultNamespace() on a parent node, AXIOM assignes a
blank namespace on the first level's child element. So if XML is passed to
AXIOM that looks like this:
<outerTag>
<innerTag>
<node1>Hello</node1>
<node2>Hello</node2>
</innerTag>
</outerTag>
And then declareDefaultNamespace() of "http://someNamespace" is called on
the <outerTag>, the resulting XML will be this:
<outerTag xmlns="http://someNamespace">
<innerTag xmlns="">
<node1>Hello</node1>
<node2>Hello</node2>
</innerTag>
</outerTag>
Notice the xmlns="" declared in the <innerTag>. According to my
understanding of XML namespaces, the <innerTag> and its child nodes will no
longer belong to the parent namespace of "http://someNamespace", since it
explicitly overrides it with an empty namespace. So <innerTag> and its
child nodes will in fact not belong to any namespace! Here is a small
program to illustrate:
import org.apache.axiom.om.*;
import org.apache.axiom.om.impl.llom.util.*;
public class Test2 {
public static void main(String [] args) {
try {
String xmlString =
"<outerTag>" +
"<innerTag>" +
"<node1>Hello</node1>" +
"<node2>Hello</node2>" +
"</innerTag>" +
"</outerTag>";
OMElement elem = AXIOMUtil.stringToOM(xmlString);
elem.declareDefaultNamespace("http://someNamespace");
System.out.println(elem.toString());
}
catch(Exception e) {
e.printStackTrace();
}
}
}
The output of this program is this (I added line breaks in the XML for
easier readability):
<outerTag xmlns="http://someNamespace">
<innerTag xmlns="">
<node1>Hello</node1>
<node2>Hello</node2>
</innerTag>
</outerTag>
As you can see, the <innerTag> was assigned xmlns="" by AXIOM.
--
View this message in context:
http://www.nabble.com/OMElement.declareDefaultNamespace%28%29-declares-empty-namespace-for-child-element.-tf4779194.html#a13672052
Sent from the Axis - Dev mailing list archive at Nabble.com.
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]