473,385 Members | 1,838 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,385 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 38773

"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: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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
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...

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.