axis-java-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Aleksander Slominski <>
Subject Re: [Axis2] Namespace serialization problem
Date Mon, 20 Dec 2004 06:59:24 GMT
Ajith Ranabahu wrote:

>Well, there is! here is the slightly modified code 
>       OMFactory factory = OMFactory.newInstance();
>       OMNamespace ns1 = factory.createOMNamespace("bar","x");
>       OMElement root = factory.createOMElement("root",ns1);
>       OMNamespace ns2 = root.declareNamespace("bar","y");
>       OMElement elt1 = factory.createOMElement("foo",ns1);
>       OMElement elt2 = factory.createOMElement("yuck",ns2);
>       OMText txt1 = factory.createText(elt2,"blah");
>       elt2.addChild(txt1);
>       elt1.addChild(elt2);
>       root.addChild(elt1);
>       SimpleOMSerializer serializer = new SimpleOMSerializer();
>       serializer.serialize(root, writer);
>And the resulting output
><x:root xmlns:x="bar" xmlns:y="bar">
> <x:foo>
>     <y:yuck>blah</y:yuck>
>  </x:foo>
>I guess this is better than the earlier one but note that you have to
>EXPLICITLY declare the namespace!. What I meant to show you guys is
>that even when you don't declare the namespaces this way, it is better
>if we can have the same serialization. Otherwise if we have more
>elements we will probably see XML's like the following (if the
>declarenamespace method is NOT used).
><x:root xmlns:x="bar">
> <y:yuck xmlns:y="bar"></y:yuck>
> <y:yuck xmlns:y="bar"></y:yuck>
>Of course this is perfectly valid but if we can push the 'y' namespace
>declaration up the tree it will be better. Currently the serializer
>does not try to optimize the namespace declarations.
>thoughts ?
simple serializer should not try to optimize for it.

if user wants to have namespace declarations on top level element then 
user has to actually declare them otherwise you get into "mind reading" 
APIs ;-)


The best way to predict the future is to invent it - Alan Kay

View raw message