如果缺少值,我想删除大xml文件中的一些元素。
我发现了一个主题,其中说明了如何提取存在值的元素,而不是相反的方式。解决方案可以是sed或xmlstactlet,但我无法理解。
xmlstarlet ed -d '//eslXmlDto[.//itemAssociations]' < file1.xml >> file2.xml
这是我的档案
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<screens>
<screenXmlDto>
<articleCodeType>EAN</articleCodeType>
<creationDate>2017-04-25T12:23:18.746+02:00</creationDate>
<domain>toto.tata</domain>
<screenCode>16201000032884264000</screenCode>
<itemAssociations>
<itemCode>2118550000000</itemCode>
<position>1</position>
</itemAssociations>
</screenXmlDto>
<screenXmlDto>
<articleCodeType>EAN</articleCodeType>
<creationDate>2016-07-27T03:59:17.328+02:00</creationDate>
<domain>toto.tata</domain>
<screenCode>17201000030538183370</screenCode>
</screenXmlDto>
<screenXmlDto>
<articleCodeType>EAN</articleCodeType>
<creationDate>2016-07-26T12:28:20.815+02:00</creationDate>
<domain>toto.tata</domain>
<screenCode>17201000030538091000</screenCode>
<itemAssociations>
<itemCode>4008033444958</itemCode>
<position>1</position>
</itemAssociations>
</screenXmlDto>
</screens>
这是我想要的输出
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<screens>
<screenXmlDto>
<articleCodeType>EAN</articleCodeType>
<creationDate>2017-04-25T12:23:18.746+02:00</creationDate>
<domain>toto.tata</domain>
<screenCode>16201000032884264000</screenCode>
<itemAssociations>
<itemCode>2118550000000</itemCode>
<position>1</position>
</itemAssociations>
</screenXmlDto>
<screenXmlDto>
<articleCodeType>EAN</articleCodeType>
<creationDate>2016-07-26T12:28:20.815+02:00</creationDate>
<domain>toto.tata</domain>
<screenCode>17201000030538091000</screenCode>
<itemAssociations>
<itemCode>4008033444958</itemCode>
<position>1</position>
</itemAssociations>
</screenXmlDto>
</screens>