I have a XML document
<ns1:Product>
<ns1:ProductDetails>
<ns1:StationID>1</ns1:StationID>
<ns1:ProductGroup>1</ns1:ProductGroup>
<ns1:AccountCode>1</ns1:AccountCode>
<ns1:Amount>1345</ns1:Amount>
</ns1:ProductDetails>
<ns1:ProductDetails>
<ns1:StationID>1</ns1:StationID>
<ns1:ProductGroup>1</ns1:ProductGroup>
<ns1:AccountCode>2</ns1:AccountCode>
<ns1:Amount>35471</ns1:Amount>
</ns1:ProductDetails>
<ns1:ProductDetails>
<ns1:StationID>1</ns1:StationID>
<ns1:ProductGroup>1</ns1:ProductGroup>
<ns1:AccountCode>3</ns1:AccountCode>
<ns1:Amount>31897</ns1:Amount>
</ns1:ProductDetails>
<ns1:ProductDetails>
<ns1:StationID>1</ns1:StationID>
<ns1:ProductGroup>1</ns1:ProductGroup>
<ns1:AccountCode>4</ns1:AccountCode>
<ns1:Amount>143647</ns1:Amount>
</ns1:ProductDetails>
<ns1:ProductDetails>
<ns1:StationID>1</ns1:StationID>
<ns1:ProductGroup>1</ns1:ProductGroup>
<ns1:AccountCode>5</ns1:AccountCode>
<ns1:Amount>34531</ns1:Amount>
</ns1:ProductDetails>
I have able to count the total number of records using Java as 5. I have few requirement in which i have to remove some records before processing further. Say for example I have to remove 3rd and 5th ProductDetails from the XML
Base on the record Position details I have to remove the 2 record
Final Output
<ns1:Product>
<ns1:ProductDetails>
<ns1:StationID>1</ns1:StationID>
<ns1:ProductGroup>1</ns1:ProductGroup>
<ns1:AccountCode>1</ns1:AccountCode>
<ns1:Amount>1345</ns1:Amount>
</ns1:ProductDetails>
<ns1:ProductDetails>
<ns1:StationID>1</ns1:StationID>
<ns1:ProductGroup>1</ns1:ProductGroup>
<ns1:AccountCode>2</ns1:AccountCode>
<ns1:Amount>35471</ns1:Amount>
</ns1:ProductDetails>
<ns1:ProductDetails>
<ns1:StationID>1</ns1:StationID>
<ns1:ProductGroup>1</ns1:ProductGroup>
<ns1:AccountCode>4</ns1:AccountCode>
<ns1:Amount>143647</ns1:Amount>
</ns1:ProductDetails>
</ns1:Product>
Can some one please help be to active this in Java Code!