tags:

views:

42

answers:

1

Hi,

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>
A: 

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.

Joe Zitzelberger
It is a working solution but I had to write lot of java(more than 100 lines) code and I am not happy about it. I am still looking for a better solution.
firemonkey