This is archived documentation for an older version of Nirvana (v2.0). Please refer to documentation for the latest version if required.

Using XML with Nirvana

Nirvana provides inbuilt support for XML based messaging.

XML can be published as either a String or a DOM Document object.

A summary of the code needed to publish and consume XML data is provided below. For more information please see the Nirvana publish XML and consume XML examples.

The code to read an XML file and publish it as DOM Document is as follows:

//Create an input stream
InputStream is = new FileInputStream( aFile );

//Create a DOM Parser object
DOMParser p = new DOMParser();

//Parse from the input stream
p.parse( new InputSource( is ) );

//Get the XML Document
doc = p.getDocument();

//Publish the Dom Document
myChannel.publish( tag, doc )

The code to consume XML is as follows:

void go( nConsumeEvent evt ) {
    //get the DOM Document from the Nirvana event
    Document doc = evt.getDocument()>

    //pass it to the Nirvana xmlHelper class
    xmlHelper xh = new xmlHelper( doc );

    //output the XML to standard out
    xh.dumpDoc();
}