Feeds

Hands on with Java XML filter pipelines

Ignored by many

3 Big data security analytics techniques

Setting up a pipeline

Once you have your filter set up and compiled, you need to create a pipeline for processing your XML. This should move from input XML document to the filter to the reader. You may even have multiple filters, stacked upon each other. As long as input comes first, and your reader (with application-specific callbacks) comes last, things work fine.

The following listings show how to set up a program to use filters. To do this we have defined a simple XML application (called SimpleXMLApplication). This is a standard SAX Content Handler (it extends the DefaultHandler to obtain the default behaviour). This application merely echoes, to the standard output, the XML passed to it (with suitable indentation).

sax content handler

The XMLFilterTest test harness class links the SimpleXMLFilter and the SimpleXMLAPplication together. Notice that because the one or more filters must sit between input source and the reader, all the operations that you would normally invoke on the reader are invoked on the filter. It then delegates any data that passes through the filter to the reader.

p>java pipeline simple application XMLFilterTest

Also note that we obtain the XMLReader form the root parse and set that as the "parent" of the filter. We then link the filter with the application by making the application the content and document handler of the filter.

The effect of running the XMLFilterTest on a simple XML document is presented below:

effect of running the XMLFilterTest

Data Pollution

However, a word of warning if you use a filter to remove some elements form the data input to the next element in the pipeline. It is all too easy to pollute the data being sent on. For example, consider the case where you don't delegate in the startElement() method for certain data, but forget to do the same in endElement(). The result would be that some elements would never be reported as starting, but would be reported to the reader as ending. This would cause, in the best case, program errors, and in the worst case, data loss or corruption in your application.

Real world use

As an example of a tool that makes extensive use of pipelines of filters, consider the DeltaXML XML diff tool. This uses XML filters to pre and post process XML data before performing XML comparisons, synchronization operations and patches. To download a time limited copy of DeltaXML see the DeltaXML web site here. ®

SANS - Survey on application security programs

More from The Register

next story
This time it's 'Personal': new Office 365 sub covers just two devices
Redmond also brings Office into Google's back yard
Oh no, Joe: WinPhone users already griping over 8.1 mega-update
Hang on. Which bit of Developer Preview don't you understand?
Microsoft lobs pre-release Windows Phone 8.1 at devs who dare
App makers can load it before anyone else, but if they do they're stuck with it
Half of Twitter's 'active users' are SILENT STALKERS
Nearly 50% have NEVER tweeted a word
Next Windows obsolescence panic is 450 days from … NOW!
The clock is ticking louder for Windows Server 2003 R2 users
Ditch the sync, paddle in the Streem: Upstart offers syncless sharing
Upload, delete and carry on sharing afterwards?
Microsoft TIER SMEAR changes app prices whether devs ask or not
Some go up, some go down, Redmond goes silent
Batten down the hatches, Ubuntu 14.04 LTS due in TWO DAYS
Admins dab straining server brows in advance of Trusty Tahr's long-term support landing
prev story

Whitepapers

SANS - Survey on application security programs
In this whitepaper learn about the state of application security programs and practices of 488 surveyed respondents, and discover how mature and effective these programs are.
Combat fraud and increase customer satisfaction
Based on their experience using HP ArcSight Enterprise Security Manager for IT security operations, Finansbank moved to HP ArcSight ESM for fraud management.
The benefits of software based PBX
Why you should break free from your proprietary PBX and how to leverage your existing server hardware.
Top three mobile application threats
Learn about three of the top mobile application security threats facing businesses today and recommendations on how to mitigate the risk.
3 Big data security analytics techniques
Applying these Big Data security analytics techniques can help you make your business safer by detecting attacks early, before significant damage is done.