XML Manipulation with Apache AXIOM, Page 3
During the serialization, a directly created namespace from the factory will be added to the declarations only when that prefix is encountered by the serializer. You will learn how to serialize Axiom elements in the next article; however, if you serialize the element you created, you get the following output.
<ns:book xmlns:ns="axis2"> <ns:name></ns:name> <ns:isbn></ns:isbn> </ns:book>
Sample 6: Working with Attributes
Now, see how to create and add attributes to the book element.
OMAttribute type = factory.createOMAttribute("type",null,"web-services"); root.addAttribute(type);
If you serialize the element again, you will see the following output:
<ns:book xmlns:ns="axis2" type="web services"> <ns:name></ns:name> <ns:isbn></ns:isbn> </ns:book>
In this article, I discussed a little bit of the history of Axiom and various ways of manipulating XML, especially the pull and push models. Then, I went though a few examples to give you an idea about Axiom XML APIs. In the next article, I will discuss more about XML navigation, Xpaths, and SOAP manipulation with Axiom.
About the Author
Deepal Jayasinghe is a Computer Science graduate student. Before starting his studies, he worked at WSO2 Inc. He is an Apache Member and active contributor to Apache Axis2 and other Apache Web services projects.
Page 3 of 3