My favorites | Sign in
Project Home
READ-ONLY: This project has been archived. For more information see this post.
Search
for
QuickStartGuide  
Quick Start Guide
Updated Oct 19, 2012 by alex.ro...@sensiasoftware.com

Parsing SWE Common Data embedded in XML

SWE Common XML data can be parsed from a file using the following code :

DOMHelper dom = new DOMHelper(fileUrl, false);
SWECommonUtils utils = new SWECommonUtils();
DataComponent sweData = utils.readComponent(dom, dom.getBaseElement());

The DOMHelper object is a wrapper around the DOM API that allows accessing and appending XML elements and attributes to a DOM tree using "path-like" strings that look like simplified XPath (it works only for simple paths but is much faster that any existing XPath engine).

A DOMHelper can also be instantiated from a Java InputStream :

DOMHelper dom = new DOMHelper(inputStream, false);

The second argument can be set to true to trigger XML validation. It can also be instantiated from a pre-existing DOM tree :

org.w3c.dom.Document doc;
DOMHelper dom = new DOMHelper(doc);

If the SWE Common is only a part of the XML document (for instance if it is contained within a O&M observation or sensorML document), you can still use DOMHelper to access the XML element containing the SWE Common content (i.e. the element in the swe namespace) and parse it with the library

For instance to parse the result of an Observation encoded as SWE Common, you can use the following code :

SWECommonUtils utils = new SWECommonUtils();
DOMHelper dom = new DOMHelper(fileUrl, false);
Element resultElt = dom.getElement("Observation/result");
DataComponent sweData = utils.readComponentProperty(dom, resultElt);

The read methods of SWECommonUtils all return a DataComponent object that contains the definition and structure of the data as well as the data values themselves.

Manipulating DataComponent objects

Comment by cusmaima...@gmail.com, Nov 11, 2012

Hi Alex, i am thinking to use this library in some projects.

I have some difficult to understand how i have to use the code, for example in order to access to a DataArray? with a DataRecord? nested.

Could you please advise me some links or documents?

Thanks a lot, Matteo.

Powered by Google Project Hosting