Results 1 to 3 of 3

Thread: [RESOLVED] Odd XPath behavior

  1. #1

    Thread Starter
    Code Monkey wild_bill's Avatar
    Join Date
    Mar 2005
    Location
    Montana
    Posts
    2,993

    Resolved [RESOLVED] Odd XPath behavior

    Why does the following code produce 'WILD' rather than 'BILL'?

    Code:
    Dim xml As String = _
    "<ROOT>" & _
    " <CHILD1>" & _
    "  <NAME>WILD</NAME>" & _
    " </CHILD1>" & _
    " <CHILD2>" & _
    "  <NAME>BILL</NAME>" & _
    " </CHILD2>" & _
    "</ROOT>"
    
    Dim doc As New XmlDocument
    doc.LoadXml(xml)
    Dim child2 As XmlNode = doc.SelectSingleNode("//CHILD2")
    Dim name As Xml.XmlNode = child2.SelectSingleNode("//NAME")
    Debug.WriteLine(name.InnerText)
    That is the very essence of human beings and our very unique capability to perform complex reasoning and actually use our perception to further our understanding of things. We like to solve problems. -Kleinma

    Does your code in post #46 look like my code in #45? No, it doesn't. Therefore, wrong is how it looks. - jmcilhinney

  2. #2

    Thread Starter
    Code Monkey wild_bill's Avatar
    Join Date
    Mar 2005
    Location
    Montana
    Posts
    2,993

    Re: Odd XPath behavior

    Found a solution to my problem
    Code:
    Dim child2 As XmlNode = doc.SelectSingleNode("//CHILD2")
    Dim name As Xml.XmlNode = child2.SelectSingleNode("descendant::NAME")
    Debug.WriteLine(name.InnerText)
    That is the very essence of human beings and our very unique capability to perform complex reasoning and actually use our perception to further our understanding of things. We like to solve problems. -Kleinma

    Does your code in post #46 look like my code in #45? No, it doesn't. Therefore, wrong is how it looks. - jmcilhinney

  3. #3
    PowerPoster
    Join Date
    Mar 2002
    Location
    UK
    Posts
    4,780

    Re: [RESOLVED] Odd XPath behavior

    I would guess that the // is forcing it to start back at the root node. Guess lookup how the xpath syntax works to get the answer.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width