Parse XML structure in .net 2
I have the following xml fragment
<converters c1="XXX" c2="ZZZ">
<converter c1="YYY" c2="ZZZ"
buy="0.9989907开发者_StackOverflow社区0428571424" 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>
I am trying to retrieve the value of the number in the "buy" attribute for the converter that has c1="XXX" and c2="ZZZ".
I can't use linq to XML unfortunatley or this would be easy (for me). So I guess I am stuck using xpath
I've created an XPathNavigator but can't get the syntax to get the valu I want
Anyone, any idea how to do this?
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*/)
}
If you use XPathDocument you can do
foreach (XPathNavigator buy in new XPathDocument("input.xml").CreateNavigator().Select("converters/converter[@c1 = 'XXX' and @c2 = 'ZZZ']/@buy"))
{
Console.WriteLine(buy.Value);
}
精彩评论