C# and XML simple problem

Discussion in 'C#' started by lkytmr, Apr 11, 2008.

  1. lkytmr

    lkytmr New Member

    Joined:
    Apr 11, 2008
    Messages:
    2
    Likes Received:
    0
    Trophy Points:
    0
    Occupation:
    Engineering
    Location:
    Louisville,KY
    I have programmed in VB6 and VC but I am new to C# and XML and I can't seem to muddle my way through the simplest of problems.

    Given an XML file below, I just want to know what the value of PI is. Why doesn't this work?

    N = root.SelectSingleNode("descendant::variable[name='PI']");
    Debug.Print(N.InnerText);

    Thanks for listening.

    Tom

    XML File:
    <?xml version="1.0"?>
    <!-- Simple test XML file -->
    <bookstore xmlns:bk="urn:samples">
    <Variables>
    <Variable name="PI"> 3.1415926535 </Variable>
    <Variable name="Four"> 4 </Variable>
    </Variables>
    </bookstore>
     
  2. lkytmr

    lkytmr New Member

    Joined:
    Apr 11, 2008
    Messages:
    2
    Likes Received:
    0
    Trophy Points:
    0
    Occupation:
    Engineering
    Location:
    Louisville,KY
    Eventually found the answer. For anyone else stuck on this:

    XmlNode N; string sVariable;

    N = root.SelectSingleNode("//descendant::variable[name='pi']/value");
    if (N != null)
    {
    sVariable = N.InnerText;
    Debug.Print(sVariable);
    }
    Tom
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice