August 23, 2014
Hot Topics:
RSS RSS feed Download our iPhone app

XML Manipulation with Apache AXIOM

  • January 30, 2009
  • By Deepal Jayasinghe
  • Send Email »
  • More Articles »

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>

Summary

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



Comment and Contribute

 


(Maximum characters: 1200). You have characters left.

 

 


Sitemap | Contact Us

Rocket Fuel