Can you please suggest the best approach for my requirement(below) in Java. I have tried using XPath but I had to recreate the whole XML. I am hoping if there is a simple way of doing this.
I want to remove nodes whose xnuy != 1
Sample input XML:
<object-stream>
<com.vo.ShapeEventsVO>
<mtx>198.0</mtx>
<mty>79.0</mty>
<xnuy>1</xnuy>
</com.vo.ShapeEventsVO>
<com.vo.ShapeEventsVO>
<mtx>198.0</mtx>
<mty>79.0</mty>
<xnuy>1</xnuy>
</com.vo.ShapeEventsVO>
<com.vo.ShapeEventsVO>
<mtx>198.0</mtx>
<mty>79.0</mty>
<xnuy>2</xnuy>
</com.vo.ShapeEventsVO>
</object-stream>
output XML:
<object-stream>
<com.vo.ShapeEventsVO>
<mtx>198.0</mtx>
<mty>79.0</mty>
<xnuy>1</xnuy>
</com.vo.ShapeEventsVO>
<com.vo.ShapeEventsVO>
<mtx>198.0</mtx>
<mty>79.0</mty>
<xnuy>1</xnuy>
</com.vo.ShapeEventsVO>
</object-stream>
Write a trivial SAX document handler — on every END ELEMENT event for com.vo.ShapeEventsVO, look at the xnuy, if it fits, write that ShapeEventsVO into a new document.
You will need to track only the most recent mty, mtd and xnuy to have all the data you need to produce the new, xnuy==1 document.