[
http://issues.apache.org/jira/browse/WSCOMMONS-74?page=comments#action_12429456
]
Eran Chinthaka commented on WSCOMMONS-74:
-----------------------------------------
Hang on guys.
Let me explain a lil bit abt this as I was involved in almost all the
discussions related to OM since 1960s ;).
The meaning of OMElement omEle = fac.createOMElement("Foo", null) means, I
don't care about the ns of this object, create an OMElement with null
namespace. When we serialize this element Foo will be assigned to default
namespace, which is automatic. Basically no ns prefix will be assigned to Foo
Putting the namespace when we create the OMElement was just a convenience
method. But if we want work with default namespaces, there aren't any
createOMElement method for that. You have to first create the OMElement then
call declareDefaultNamespace.
This was agreed sometime back I think (I can not find the mail or the comment I
put in a commit)
So if we want to create what Ruchith wanted to do, this is the proper code
fragment.
If you to get
<person xmlns="http://ws.apache.org/axis2/apacheconasia/06"><name
xmlns="">John</name><age>34</age><weight>50</weight></person>
OMFactory fac = OMAbstractFactory.getOMFactory();
OMElement personElem = fac.createOMElement("person", null);
OMNamespace ns =
personElem.declareDefaultNamespace("http://ws.apache.org/axis2/apacheconasia/06");
//Create and add an unqualified element
OMElement nameElem = fac.createOMElement("name", null);
nameElem.declareDefaultNamespace("\"\"");
nameElem.setText("John");
personElem.addChild(nameElem);
OMElement ageElem = fac.createOMElement("age", null); // even if this
is ("age", ns) there is no change in
// this case
ageElem.setText("34");
OMElement weightElem = fac.createOMElement("weight", ns);
weightElem.setText("50");
personElem.addChild(ageElem);
personElem.addChild(weightElem);
P.S. Rich you have six more days to go, I'm now 17 days after it :)
> Incorrect namespace serialization
> ---------------------------------
>
> Key: WSCOMMONS-74
> URL: http://issues.apache.org/jira/browse/WSCOMMONS-74
> Project: WS-Commons
> Issue Type: Bug
> Components: AXIOM
> Reporter: Ruchith Udayanga Fernando
> Assigned To: Rich Scheuerle
> Priority: Blocker
> Attachments: axiom_api_patch.txt, axiom_impl_patch.txt,
> axiom_test_patch.txt, jaxsw_test_patch.txt, SerializationTest.java
>
>
> Hi All,
> I noticed that axiom doesn't serialize namespaces correctly.
> 1.) Namespaces in qualified elements
> For example we should be able to produce the following xml with the code that
> follows:
> <person1 xmlns="http://ws.apache.org/axis2/apacheconasia/06">
> <name>John</name>
> <name>John12</name>
> <age>34</age>
> </person1>
> OMFactory fac = OMAbstractFactory.getOMFactory();
>
> OMNamespace ns =
> fac.createOMNamespace("http://ws.apache.org/axis2/apacheconasia/06", "");
> OMElement personElem = fac.createOMElement("person", ns);
> OMElement nameElem = fac.createOMElement("name", ns);
> nameElem.setText("John");
>
> OMElement ageElem = fac.createOMElement("age", ns);
> ageElem.setText("34");
>
> OMElement weightElem = fac.createOMElement("weight", ns);
> weightElem.setText("50");
>
>
> //Add children to the person element
> personElem.addChild(nameElem);
> personElem.addChild(ageElem);
> personElem.addChild(weightElem);
>
> String xml = personElem.toString();
> But right now this produces the following :
> <person xmlns="http://ws.apache.org/axis2/apacheconasia/06"><name
> xmlns="http://ws.apache.org/axis2/apacheconasia/06">John</name><age
> xmlns="http://ws.apache.org/axis2/apacheconasia/06">34</age><weight
> xmlns="http://ws.apache.org/axis2/apacheconasia/06">50</weight></person>
> The repetition of the default namespace should be avoided.
> This is the same even if we used a prefixed namespace.
> 2.) Unqualified elements among qualified elements
>
> OMFactory fac = OMAbstractFactory.getOMFactory();
> OMNamespace ns =
> fac.createOMNamespace("http://ws.apache.org/axis2/apacheconasia/06", "");
> OMElement personElem = fac.createOMElement("person", ns);
> //Create and add an unqualified element
> OMElement nameElem = fac.createOMElement("name", null);
> nameElem.setText("John");
> personElem.addChild(nameElem);
> OMElement ageElem = fac.createOMElement("age", ns);
> ageElem.setText("34");
>
> OMElement weightElem = fac.createOMElement("weight", ns);
> weightElem.setText("50");
> personElem.addChild(ageElem);
> personElem.addChild(weightElem);
> System.out.println(personElem);
> The above should produce the following :
> <person xmlns="http://ws.apache.org/axis2/apacheconasia/06"><name
> xmlns="">John</name><age>34</age><weight>50</weight></person>
> But AXIOM right now produces :
> <person
> xmlns="http://ws.apache.org/axis2/apacheconasia/06"><name>John</name><age
> xmlns="http://ws.apache.org/axis2/apacheconasia/06">34</age><weight
> xmlns="http://ws.apache.org/axis2/apacheconasia/06">50</weight></person>
> What do u folks think?
> Thanks,
> Ruchith
> p.s. Added a test case
--
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
http://issues.apache.org/jira/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]