Apache AXIOM and XML Manipulations

Axiom acronym stand as AXis2 Object Model. It is the part of the Axis2 project and it is now consider as the component of WS components.

Axiom is the main XML representation mechanism in Axis2, so any message coming to Axis2 will be represented as an Axiom object in Axis2.  DOM and JDOM are two classic examples for such XML models. AXIOM is conceptually similar to such a XML model by its external behaviour, but deep down it is very different.

AXIOM i lightweight info-set representation of XML based on StAX, which is the standard streaming pull parser API. The object model can be manipulated flexibly as any other object model (such as JDOM), but the objects will be created only when they are absolutely required.

Hey Nifras! What you mean by pull parsing and push parsing?

I am hearing your mind voice. :-P 

XML documents can be parsed using a "pull-based" or a "push-based" (StAX) process. Now the trend on pull parsing is PULL parsing.The previously popular frameworks like SAX and DOM uses PUSH passing (SAX) process. 

So What is differ this ? 
pull parsing refers to a programming model in which a client application calls methods on an XML parsing library when it needs to interact with an XML infoset; that is, the client only gets (pulls) XML data when it explicitly asks for it.

push parsing refers to a programming model in which an XML parser sends (pushes) XML data to the client as the parser encounters elements in an XML infoset; that is, the parser sends the data whether or not the client is ready to use it at that time.

Now Let's work with AXIOM

If we need to work with AXIOM we need to download the AXIOM binary distributions or AXIOM source code distribution. The add the AXIOM into your class path. If you are using maven then add that into your maven dependency. 

Let's Creating AXIOM

We can create AXIOM in three ways. 

  1. create using pull event stream (StAX).
  2. create using push event stream (SAX).
  3. create using programmatically.


Let's have a look with create usgin pull event strream (StAX), 

The factory helps keep the code at the interface level and the implementations separately. Because Axiom is tightly bound to StAX, a StAX compliant reader should be created first with the desired input stream. 

Then, you can select one of the many builders available. In Axiom, you can find different types of builders as well, and those are mainly for user convenience. Axiom has OM builders as well as SOAP builders, so you can use the appropriate builder for your requirement. 

StAXOMBuilder will build a pure XML infoset-compliant object model whereas the SOAPModelBuilder returns SOAP-specific objects (such as the SOAPEnvelope, which are sub classes of the OMElement) through its builder methods.

Example 1 : Creating AXIOM from the input file stream. 


Example 2 : Creating AXIOM from the String

Example 3 : Create AXIOM programmatically 

Example 4: Adding a Child Node and Attributes

The following are important method for adding axiom child and attributes. 

Sample 5: Working with OM Namespaces

Namespace handling is the key part in XML processing. This will provide by some set of XML APIs.


6: Working with Attributes

Now we will see how to add attributes

Comments

Popular posts from this blog

Missionaries & Canibal Problem in AI using Pro Log

Hide the navigation bar in jHipster Angular 2

Spring Boot - No Need to Restart the Development Server for Each Time