[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

XML navigation in VB .NET

Posted on 2009-05-04
4
Medium Priority
?
241 Views
Last Modified: 2012-05-06
I am new to xml navigation in .NET so I have a fairly basic question I hope someone can help me with.

I have a xml file with a similar structure as shown below. I iterate through the node list and find the node I need based on field1. However I am not sure how I can reach the value I need which is field2.

Maybe it is a better approach to set the navigator to ""/message/value" and then retreive each child individually. If so any advise of the syntax will be very good.

Thanks J
<?xml version="1.0" encoding="iso-8859-1"?>
<message>
  <value>
    <field1>0001</field1>
    <field2>This is the text I need for 0001</field2>
  </value>
  <value>
    <field1>0002</field1>
    <field2>This is the text I need for 0002</field2>
  </value>
</message>
 
 
  Dim xpathDoc As XPathDocument
        Dim xmlNav As XPathNavigator
        Dim xmlNI As XPathNodeIterator
 
        Dim _strValue As String = ""
 
 
        xpathDoc = New XPathDocument("C:\test.xml")
        xmlNav = xpathDoc.CreateNavigator()
 
 
       xmlNI = xmlNav.Select("/message/value/field1")
 
            While (xmlNI.MoveNext())
 
                If xmlNI.Current.Value = "0001" Then
                    _strValue= some code here to retrieve value "This is the text I need 0001"
                    Exit While
                End If
 
            End While

Open in new window

0
Comment
Question by:jes12345
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
4 Comments
 
LVL 6

Accepted Solution

by:
mvgeertruyen earned 2000 total points
ID: 24295649
Not perfect but answers your question:
        xmlNI = xmlNav.Select("/message/value")
 
        While (xmlNI.MoveNext())
 
            If xmlNI.Current.SelectSingleNode("field1").Value = "0001" Then
                '_strValue= some code here to retrieve value "This is the text I need 0001"
                Debug.Write(xmlNI.Current.SelectSingleNode("field2"))
                Exit While
            End If
 
        End While

Open in new window

0
 

Author Comment

by:jes12345
ID: 24297265
Thanks for the advise - I have left the office for the day but will test it out first thing.
Thanks J
0
 

Author Comment

by:jes12345
ID: 24302411
Woked like a charm - many thanks for the advise! J
0
 

Author Closing Comment

by:jes12345
ID: 31577524
I think it was perfect:)
0

Featured Post

Nothing ever in the clear!

This technical paper will help you implement VMware’s VM encryption as well as implement Veeam encryption which together will achieve the nothing ever in the clear goal. If a bad guy steals VMs, backups or traffic they get nothing.

Question has a verified solution.

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

Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Suggested Courses

656 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