2011-01-25 115 views
0

我有下面的XML片段解析XML結構2

<converters c1="XXX" c2="ZZZ"> 
    <converter c1="YYY" c2="ZZZ" 
       buy="0.99899070428571424" sell="0.99966215285714288" /> 
    <converter c1="XXX" c2="YYY" 
       buy="1.5503238471428571" sell="1.550773867142857" /> 
    <converter c1="XXX" c2="ZZZ" 
       buy="1.5487591119281807" sell="1.5502499426226253" /> 
</converters> 

我試圖找回在「買」屬性的轉換器,具有C1 =「XXX」數的值和C2 = 「ZZZ」。

我不能使用linq來XML unfortunatley或這將是容易的(對我來說)。所以我想我使用XPath的卡住

我創建的XPathNavigator,但不能得到語法得到VALU我想

任何人,任何想法如何做到這一點?

回答

1

如果你使用的XPathDocument你可以做

foreach (XPathNavigator buy in new XPathDocument("input.xml").CreateNavigator().Select("converters/converter[@c1 = 'XXX' and @c2 = 'ZZZ']/@buy")) 
{ 
    Console.WriteLine(buy.Value); 
} 
2
XmlDocument doc = new XmlDocument(); 
       doc.LoadXml(""); 
       XmlNodeList list = doc.SelectNodes("converters/converter"); 

       foreach (XmlNode element in list) 
       { 
        if (element.Attributes["c1"].Value == "XXX" /*other operations*/) 

       }