night sailor

night sailor

  • NA
  • 20
  • 39k

Strange Problem

Jan 13 2011 6:48 AM
Hi...

I am using this xml:


<xml>
  <employee>

    <person>
      <name>a</name>
      <lucky>80</lucky>
      <send>
        <name1>b</name1>
      </send>
    </person>

    <person>
      <name>c</name>
      <lucky>160</lucky>
      <send>
        <name1>d</name1>
      </send>
    </person>

  </employee>
</xml>

And this is some part part of my code :

            XmlNodeList nameList = xmldoc.SelectNodes("//employee/person");

            foreach (XmlNode nameNode in nameList)
            {
                if (nameNode.SelectSingleNode("name").InnerText == "c")
                {
                    string bug1 = nameNode.SelectSingleNode("//send/name1").InnerText;
                    string bug2 = nameNode.SelectSingleNode("lucky").InnerText;
                }
            }

On executing this code, i should expect

bug1 =  d
bug2 = 160

but i am getting

bug1 = b
bug2 = 160

Please help...Tell me if i am wrong in selecting node (//send/name1)....

Thanks

Answers (3)