0

I have the following xml fragment

<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>

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?

2 Answers 2

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*/) 

                }
Sign up to request clarification or add additional context in comments.

Comments

1

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);
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.