如何获得属性的值" CONTRACT_TYPE"在下面的XML中。 xml作为字符串参数传递给我的程序。我尝试了多种方法,但无法实现。
<?xml version="1.0" encoding="UTF-8"?>
<FX_CORPORATE>
<TRADE>
<REFERENCE_NUMBER>1188586</REFERENCE_NUMBER>
<TRANSACTION_DATE>20160902</TRANSACTION_DATE>
<CONTRACT_TYPE>FX-SPOT</CONTRACT_TYPE>
<COUNTERPARTY>SRI IMEL</COUNTERPARTY>
<CROSS>NO</CROSS>
<VIA_CURRENCY>USD</VIA_CURRENCY>
<TRADER>EMXMONAB</TRADER>
<POSITION_CURRENCY>AUD</POSITION_CURRENCY>
<VALUE_DATE>20160906</VALUE_DATE>
<BUY>
<CURRENCY>AUD</CURRENCY>
<AMOUNT>35000</AMOUNT>
</BUY>
<SELL>
<CURRENCY>USD</CURRENCY>
<AMOUNT>26400.5</AMOUNT>
</SELL>
<QUOTE>
<RATE>0.7543</RATE>
</QUOTE>
<BUY_CURRENCY_RATES>
<SPOT_RATE>0.7546</SPOT_RATE>
</BUY_CURRENCY_RATES>
<SELL_CURRENCY_RATES>
<SPOT_RATE>0.7546</SPOT_RATE>
</SELL_CURRENCY_RATES>
</TRADE>
</FX_CORPORATE>
答案 0 :(得分:1)
_doc = new XmlDocument();
_doc.Load("//link to xml file");
XmlNode node = doc.SelectSingleNode("FX_CORPORATE/TRADE/CONTRACT_TYPE");
string value = node.InnerText;
这应该有效