这是我的XPath:
./trade/financeLeg/paymentDates/paymentDate[1]
这是我的xml文件:
<dataDocument>
<trade>
<underlyingSymbol />
<quantity />
<avgPrice />
<notional />
<effectiveDate />
<lookBack>0</lookBack>
<expirationDate />
<broker>Select</broker>
<exchange />
<equityLeg>
<frequency>Monthly</frequency>
<paymentDates>
<paymentDate />
</paymentDates>
<currency>USD</currency>
</equityLeg>
<financeLeg>
<resetDates>
<resetDate />
</resetDates>
<interestRate>0.00</interestRate>
<spread>0</spread>
<dayCount>ACT/360</dayCount>
<frequency>Monthly</frequency>
<paymentDates>
<paymentDate />
</paymentDates>
<currency>USD</currency>
<interestRateBenchMark>Select</interestRateBenchMark>
<marginCollateral>0.00</marginCollateral>
</financeLeg>
<dividendLeg>
<paymentDate />
<currency>USD</currency>
<dividedRate>0.00</dividedRate>
<frequency>Monthly</frequency>
</dividendLeg>
</trade>
</dataDocument>
当我在 XPathSelectElement 上使用XPath时,它返回'null',我意识到这可能是由于标记为空。但是使用Xpath获取元素的最佳方法是什么?
答案 0 :(得分:0)
/表示从根开始查找 如果您使用/,您可以尝试/ dataDocument / trade / financeLeg / paymentDates / paymentDate [1]
我相信你想用 //贸易/ financeLeg / paymentDates / PAYMENTDATE [1]
答案 1 :(得分:0)
我意识到这是因为我将XML保存为空节点,因为我将其更改为,我能够使xpath工作