-3

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!

2
  • 2
    Show us what have you tried and where did you stuck and we'll help you to move on. I'd use DOM to create a document object model and then you can add/remove nodes in model. Then you can write DOM to file again. There is a tutorial googled right now: tutorials.jenkov.com/java-xml/dom.html Commented Aug 16, 2012 at 11:55
  • See: stackoverflow.com/a/3717875/383861 Commented Aug 16, 2012 at 13:14

1 Answer 1

0

Use the standard library. I'm sorry but you've got to read the Java Tutorial :

"To remove a node, you use its parent Node's removeChild method."

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.