How to make a XPathNav select a specific node ?

Hello all !

I have the following XML file :

<?xml version="1.0" encoding="utf-8" ?>
<ITEMS count="5">
            <VALUE><![CDATA[VALUE 1]]></VALUE>
            <VALUE><![CDATA[VALUE 2]]></VALUE>

I do NOT want to use a dataset to load it and I do NOT want to use a XmlDocument.
I want to parse it that file using the XPathNavigator.

Previously, I was using
  Private m_XmlIte As XPathNodeIterator
        m_XmlDoc = New XPathDocument(New IO.StringReader(XmlLabels))
        m_XmlIte = m_XmlDoc.CreateNavigator.Select("descendant::ITEM")
and then iterating on the XPathNodeIterator to get my different values.

But I wanted to add a specific method to get directly the node I wanted (for instance, egtting firectly the second ITEM element without any MoveNext call)
And so I want to use something like :

    m_XmlIte = m_XmlDoc.CreateNavigator.Select("descendant::ITEMS[ITEM/TXT_CODE='" & txtCode & "']")

But this syntax always give me the first ITEM element.
What is the problem ? Can I do what I want with the XPathNavigator ? Is there a mistake in my XPathExpression ?

Thanks !
Who is Participating?
moduloConnect With a Mentor Commented:
Closed, 250 points refunded.

Community Support Moderator
Experts Exchange
JarodtweissAuthor Commented:
I tried
but I always have the first node
m_XmlIte = m_XmlDoc.CreateNavigator.Select("/ITEMS/ITEM/TXT_CODE")
JarodtweissAuthor Commented:

your expression is correct if I want to iterate thru all TXT_CODE tags which I do not want to do !
I really want to arrive directly at the TXT_CODE I want.
I tried
but that gives me an exception !
JarodtweissAuthor Commented:
I found the answer !
I use now :

    Dim myExpr As Xml.XPath.XPathExpression
    myExpr = myNav.Compile("descendant::ITEM[TXT_CODE='txt0008']")
    myIte = myNav.Select(myExpr)

I close the question
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.