reading an xml file for a value

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

hey all,

all i'm trying to do is retrieve text value from a particular node. and i
can get it the way shown below but was wondering if there was a cleaner way.
Because right now i'm looping thru the xml file looking for a particular node
and when it finds it i go ahead and read one more time to advance to the
value of the node. is this how it's normally done?


Do While (reader.Read())
Select Case reader.NodeType
Case XmlNodeType.Element 'Display beginning of element.
If reader.Name = "strSearch" Then
reader.Read()
RichTextBox1.AppendText(reader.Value)
End If
End Select
Loop

thanks,
rodchar
 
Hi rodchar,

That would be how I would do it, but my knowledge of XML is minimal (I'm
not a huge fan of it to be honest). I think you could also try loading
in the XML as an XmlDocument and calling SelectNodes, passing in the
appropriate XPath expression to match your strSearch nodes.

As to what that expression is, sorry, I can't help you there :)

Regards,
-Adam.
 
Rodchar,

It depends what your XML file is. When it is a document than in my opinion
the most easy is the nodereader.

When it is a dataset (that has only elements) you can read it as a dataset
(from what I get the idea) than in my opinion the most easy is..

dim ds as new dataset
ds.readxml("ThePath")

I hope this helps?

Cor
 
Back
Top