如何从xmltag内部获取价值?

时间:2018-04-10 13:55:33

标签: c# xml xmlnodelist

我从xml文档中获取了一个名为XmlNodeList的列表。我可以使用GetElementsByTagName获取innertext值。但我需要从内部标签读取值。想要阅读" USD" in" Currency CrossOrder =" 0" KOD =" USD"货币代码=" USD""一部分。

<Currency CrossOrder="0" 
          Kod="USD" 
          CurrencyCode="USD">
    <Unit>1</Unit>
    <Isim>ABD DOLARI</Isim>
    <CurrencyName>US DOLLAR</CurrencyName>
    <ForexBuying>4.0707</ForexBuying>
    <ForexSelling>4.0780</ForexSelling>
    <BanknoteBuying>4.0678</BanknoteBuying>
    <BanknoteSelling>4.0841</BanknoteSelling>
    <CrossRateUSD />
    <CrossRateOther />
</Currency>
<Currency CrossOrder="1" 
          Kod="AUD" 
          CurrencyCode="AUD">
    <Unit>1</Unit>
    <Isim>AVUSTRALYA DOLARI</Isim>
    <CurrencyName>AUSTRALIAN DOLLAR</CurrencyName>
    <ForexBuying>3.1389</ForexBuying>
    <ForexSelling>3.1594</ForexSelling>
    <BanknoteBuying>3.1245</BanknoteBuying>
    <BanknoteSelling>3.1784</BanknoteSelling>
    <CrossRateUSD>1.2938</CrossRateUSD>
    <CrossRateOther />
</Currency>

1 个答案:

答案 0 :(得分:1)

对于$primaryKey = $row['nameOfPrimaryKeyColumn']; XmlReader<Currency CrossOrder="0" Kod="USD" CurrencyCode="USD">类型的节点。

Element是此节点中的属性。 如果您想获得&#34; USD&#34;,您将获得CurrencyCode属性的值。

尝试CurrencyCode方法。

请参阅Microsoft docs