Solved

How to make a XPathNav select a specific node ?

Posted on 2004-04-28
7
339 Views
Last Modified: 2012-05-04
Hello all !

I have the following XML file :

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

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 !
0
Comment
Question by:Jarodtweiss
  • 3
7 Comments
 
LVL 4

Author Comment

by:Jarodtweiss
ID: 10939906
I tried
  descendant::ITEMS[ITEM/TXT_CODE='txt_code2']
  descendant::ITEM[TXT_CODE='txt_code2']
but I always have the first node
0
 
LVL 8

Expert Comment

by:Dranizz
ID: 10941612
m_XmlIte = m_XmlDoc.CreateNavigator.Select("/ITEMS/ITEM/TXT_CODE")
0
 
LVL 4

Author Comment

by:Jarodtweiss
ID: 10941936
Dranizz,

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
  m_XmlDoc.CreateNavigator.Select("/ITEMS/ITEM/TXT_CODE='myCode'")
but that gives me an exception !
0
 
LVL 4

Author Comment

by:Jarodtweiss
ID: 10941979
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
0
 

Accepted Solution

by:
modulo earned 0 total points
ID: 10973053
Closed, 250 points refunded.

modulo
Community Support Moderator
Experts Exchange
0

Featured Post

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Flash (http://en.wikipedia.org/wiki/Adobe_Flash) has evolved over the years to where it has become a masterful tool for displaying content screen.  It has excellent layout placement, UI precision as well as rendering capabilities. This, along with t…
In my previous article (http://www.experts-exchange.com/Programming/Languages/.NET/.NET_Framework_3.x/A_4362-Serialization-in-NET-1.html) we saw the basics of serialization and how types/objects can be serialized to Binary format. In this blog we wi…
In a recent question (https://www.experts-exchange.com/questions/28997919/Pagination-in-Adobe-Acrobat.html) here at Experts Exchange, a member asked how to add page numbers to a PDF file using Adobe Acrobat XI Pro. This short video Micro Tutorial sh…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

832 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question