我有以下xml:
<RiskDetails>
<RatingSequence direction="O" value="2"></RatingSequence>
<VehicleDetails></VehicleDetails>
<RiskFeatures></RiskFeatures>
<Drivers>
<DriverDetails></DriverDetails>
<DriverDetails></DriverDetails>
<DriverDetails></DriverDetails>
</Drivers>
<CoverDetails></CoverDetails>
<LoadDiscountDetails>
<LoadDiscount></LoadDiscount>
<LoadDiscount></LoadDiscount>
</LoadDiscountDetails>
</RiskDetails>
我需要动态地找到没有值或属性的每个子节点。我正在尝试没有成功找到返回这些节点的Xpath:
<VehicleDetails></VehicleDetails>
<RiskFeatures></RiskFeatures>
<Drivers>
<DriverDetails></DriverDetails>
<DriverDetails></DriverDetails>
<DriverDetails></DriverDetails>
</Drivers>
<CoverDetails></CoverDetails>
<LoadDiscountDetails>
<LoadDiscount></LoadDiscount>
<LoadDiscount></LoadDiscount>
</LoadDiscountDetails>
我将删除这些节点,并仅为节点及其父节点保留值:
<RiskDetails>
<RatingSequence direction="O" value="2"></RatingSequence>
</RiskDetails>
我可以按层次结构进行,但是我只尝试使用一个Xpath。
答案 0 :(得分:0)
您可以尝试在XPath
下方使用以获得所需的输出:
//RiskDetails/*[not(@* or string())]