473,395 Members | 1,977 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 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 38774

"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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

10
by: Xinyi Yang | last post by:
Hi, I have to read information out of a file. The format will be string1,string2,..., string3,string4,..., .... (the string sould not contain ' ' anyway) the size of each string is uncertain....
0
by: Ahmed A. | last post by:
This will be very helpfull for many! Using RichTextBox Read/Write Unicode File http://www.microsoft.com/indonesia/msdn/wnf_RichTextBox.as p Private Function ReadFile(ByVal myfile As String)...
4
by: Thomas Kreuzer | last post by:
Hello everyone, I have a question regarding how to interpret a string. Basically I want to write a little calculator, I will type something like "12+69*12-44/2" and then want my program to...
3
by: shaft | last post by:
hi i have the following code : string addrress; cin >> address; cout << address; if I enter any string with space in between , it will save the first word only. e.g. if i enter "this is...
5
by: lovecreatesbea... | last post by:
The condition at line 31 is added to check if the program finished to read the whole file. Is it needed and correct? Thank you. #include <fstream> #include <iostream> #include <string> using...
6
by: blinktude | last post by:
Hi I have a txt file full of words and numbers for example: ------------------------------------------------- `smash the stack` n. On many C implementations it is possible to corrupt the...
0
by: Yasin cepeci | last post by:
is it possible that read string values in a filled dataset?
1
by: boss1 | last post by:
i have textfile containing multiple rows.Each row containing same type of strings.now my problem is i can read only one row frequently but i can't read multiple rows. so how can i solve this...
1
by: Matrixinline | last post by:
Hi All, File Text.txt Contains following text as : "C:\program file\application data\details\app" "D:\Program File" I tried to read that data as fscanf(oFp, "%s %s", sCopyDirectory,...
3
by: maneshborase | last post by:
Hi friends, I am facing one serious problem in my application. I am trying to open dicom image file (.dcm) has size around 400 MB. But I am getting and unhandy exceptions, Some time, ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.