reading an xml file for a value

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
 
A

Adam Goossens

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.
 
C

Cor Ligthert

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top