471,854 Members | 1,898 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,854 software developers and data experts.

How to read xml string in vb.net?

I have a string with xml syntax.

<department>
<employee name="ABC" age="31" sex="male"/>
<employee name="CDE" age="40" sex="male"/>
</department>

How do I get the value from the xml string?

Thanks!

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 21 '05 #1
6 38642

"Terrence Chan" <te***********@fmr.com> wrote in message
news:OM**************@TK2MSFTNGP11.phx.gbl...
I have a string with xml syntax.

<department>
<employee name="ABC" age="31" sex="male"/>
<employee name="CDE" age="40" sex="male"/>
</department>

How do I get the value from the xml string?


WHICH value?
Nov 21 '05 #2
* Terrence Chan <te***********@fmr.com> scripsit:
I have a string with xml syntax.

<department>
<employee name="ABC" age="31" sex="male"/>
<employee name="CDE" age="40" sex="male"/>
</department>

How do I get the value from the xml string?


For processing XML data, take a look at the classes in the 'System.Xml'
namespace. For reading files, take a look at the classes in the
'System.IO' namespace, namely the 'StreamReader' class.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>
Nov 21 '05 #3
Terrence,

I made a simple sample from your question.

I hope it helps?

Cor
\\\\
Dim xmlString As String = "<department>" & _
"<employee name=""ABC"" age=""31"" sex=""male""/>" & _
"<employee name=""CDE"" age=""40"" sex=""male""/></department>"
Dim sr As New System.IO.StringReader(xmlString)
Dim doc As New Xml.XmlDocument
doc.Load(sr)
'or just in this case doc.LoadXML(xmlString)
Dim reader As New Xml.XmlNodeReader(doc)
While reader.Read()
Select Case reader.NodeType
Case Xml.XmlNodeType.Element
If reader.Name = "employee" Then
MessageBox.Show(reader.GetAttribute("name"))
End If
End Select
End While
///
Nov 21 '05 #4
Hi Cor,

Thank you so much for your code. It works very well.

I know it is something about the class system.xml as Herfried mentioned.
But I always have hard time to read the msdn document and found out how
the code should write. They explain the class and description not well.

May I ask how do you get the ideal of using the code below as there is
so many class and event under the system.xml class?

Thanks,
Terrence
*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 21 '05 #5
Hi Cor,

Thank you so much for your code. It works very well!!!

I know it is something about the class system.xml as Herfried mentioned.
But I always have hard time to read the msdn document and found out how
the code should write. They explain the class and description not well.

May I ask how do you get the ideal of using the code you provided as
there is so many class and event under system.xml?

Thanks,
Terrence
*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 21 '05 #6
Terrence,

I agree with you that it is one of the worsest documentated classes there
are in VBNet.

Just bringing all together will get you it working, however than it is quiet
simple as you probably saw?

Cor
"
Hi Cor,

Thank you so much for your code. It works very well.

I know it is something about the class system.xml as Herfried mentioned.
But I always have hard time to read the msdn document and found out how
the code should write. They explain the class and description not well.

May I ask how do you get the ideal of using the code below as there is
so many class and event under the system.xml class?

Thanks,
Terrence
*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!

Nov 21 '05 #7

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

10 posts views Thread by Xinyi Yang | last post: by
4 posts views Thread by Thomas Kreuzer | last post: by
5 posts views Thread by lovecreatesbea... | last post: by
1 post views Thread by Matrixinline | last post: by
reply views Thread by YellowAndGreen | last post: by
aboka
reply views Thread by aboka | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.