使用JaVa从XML中删除XML节点
我有一个XML文档
<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>
我能用Java计算出总记录数为5。我几乎没有要求在进一步处理之前删除一些记录。例如,我必须从XML中删除第三和第五个ProductDetails
根据记录位置的详细信息,我必须删除2条记录
最终产量
<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>
有人能帮我在Java代码中激活它吗
# 1 楼答案
使用标准库。很抱歉,但你必须阅读Java Tutorial: