我有一个 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 中删除第 3 和第 5 个 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 代码中激活它吗?