使用java过滤xml

使用java过滤xml,java,xml,Java,Xml,我有一个包含数据的xml文件。我需要创建一个带有某些条件的xml报告 例如: 源xml文件包含如下所示的数据 <testcase time="71.588" name="LifeActuarialRisk"> <properties> <property name="Upload_" value="P"/> <property name="Upload_" value="P"/> <property name="Uplo

我有一个包含数据的xml文件。我需要创建一个带有某些条件的xml报告

例如: 源xml文件包含如下所示的数据

<testcase time="71.588" name="LifeActuarialRisk">
  <properties>
   <property name="Upload_" value="P"/>
   <property name="Upload_" value="P"/>
   <property name="Upload_" value="F"/>
   <property name="Upload_" value="P"/>
   <property name="Upload_" value="P"/>
  </properties>
</testcase> 

我想按如下方式过滤xml

<testcase time="71.588" name="LifeActuarialRisk">
 <properties>
  <property name="Upload_" value="F"/>
 </properties>
</testcase>

谁能解释一下马歇尔和联合马歇尔数据的解决方案

测试用例域类:

@XmlRootElement
public class TestCase{

    private List<Property> logProperties = new ArrayList<Property>();

    @XmlElementWrapper(name="properties")
    @XmlElement(name="property")
    public List<Property> getLogProperties() {
        return logProperties;
    }
}
File file = new File("C:\\yourData.xml");
JAXBContext jaxbContext = JAXBContext.newInstance(TestCase.class);
Unmarshaller jaxbUnmarshaller = jaxbContext.createUnmarshaller();
TestCase aTestCase = (TestCase) jaxbUnmarshaller.unmarshal(file);

aTestCase.setProperties(aTestCase.getProperties().stream()
.filter(p -> "F".equals(p.getValue())).collect(Collectors.toList()));

Marshaller jaxbMarshaller = jaxbContext.createMarshaller();
jaxbMarshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
jaxbMarshaller.marshal(aTestCase , file);

更正了。这是我的旧代码中的一个输入错误;)您考虑过使用XSLT吗?