473,487 Members | 2,466 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Getting node names from XML

I have the follwing XML string:

<RecordSet>
<Row RowNumber="1">
<UserID>111</UserID>
<Phone>1234567890</Phone>
</Row>
<Row RowNumber="2">
<UserID>747</UserID>
<Phone>9876543210</Phone>
</Row>
</RecordSet>

A <Row> can have a variable number of elements in it.

How do I get a list of the elements? Such as in the
above case would be UserID and Phone?

My goal is to convert the XML into a Dataset.

Thanks!

Nov 21 '05 #1
6 1978
Here's one way:

Public Function GetNodes(ByVal xpathExpression As String) As String()
Dim node As XmlNode = m_root.SelectSingleNode(xpathExpression)
If node Is Nothing Then Return Nothing
Dim nodelist As XmlNodeList = node.ChildNodes
Dim s(nodelist.Count - 1) As String
Dim i As Integer = 0
For Each xnode As XmlNode In nodelist
s(i) = xnode.Name
i += 1
Next
Return s
End Function

HTH
Steve

"vbmark" <no@email.com> wrote in message
news:Xn************************@199.45.49.11...
I have the follwing XML string:

<RecordSet>
<Row RowNumber="1">
<UserID>111</UserID>
<Phone>1234567890</Phone>
</Row>
<Row RowNumber="2">
<UserID>747</UserID>
<Phone>9876543210</Phone>
</Row>
</RecordSet>

A <Row> can have a variable number of elements in it.

How do I get a list of the elements? Such as in the
above case would be UserID and Phone?

My goal is to convert the XML into a Dataset.

Thanks!

Nov 21 '05 #2
Hi Mark,
Any reason you can't just read the Xml directly into a DataSet, using
the .ReadXml() method?

Marcie

On Tue, 26 Apr 2005 19:36:59 GMT, vbmark <no@email.com> wrote:
I have the follwing XML string:

<RecordSet>
<Row RowNumber="1">
<UserID>111</UserID>
<Phone>1234567890</Phone>
</Row>
<Row RowNumber="2">
<UserID>747</UserID>
<Phone>9876543210</Phone>
</Row>
</RecordSet>

A <Row> can have a variable number of elements in it.

How do I get a list of the elements? Such as in the
above case would be UserID and Phone?

My goal is to convert the XML into a Dataset.

Thanks!


Nov 21 '05 #3
I could not get it to work for me. I'm sure that I just wasn't doing
something right.

Marcie Jones <ma*********@yahoo.com> wrote in
news:oi********************************@4ax.com:
Hi Mark,
Any reason you can't just read the Xml directly into a DataSet, using
the .ReadXml() method?

Marcie

On Tue, 26 Apr 2005 19:36:59 GMT, vbmark <no@email.com> wrote:
I have the follwing XML string:

<RecordSet>
<Row RowNumber="1">
<UserID>111</UserID>
<Phone>1234567890</Phone>
</Row>
<Row RowNumber="2">
<UserID>747</UserID>
<Phone>9876543210</Phone>
</Row>
</RecordSet>

A <Row> can have a variable number of elements in it.

How do I get a list of the elements? Such as in the
above case would be UserID and Phone?

My goal is to convert the XML into a Dataset.

Thanks!



Nov 21 '05 #4
What's m_root?

"Steve Long" <St**********@NoSpam.com> wrote in news:#dnCXtpSFHA.3244
@TK2MSFTNGP15.phx.gbl:
Here's one way:

Public Function GetNodes(ByVal xpathExpression As String) As String()
Dim node As XmlNode = m_root.SelectSingleNode(xpathExpression)
If node Is Nothing Then Return Nothing
Dim nodelist As XmlNodeList = node.ChildNodes
Dim s(nodelist.Count - 1) As String
Dim i As Integer = 0
For Each xnode As XmlNode In nodelist
s(i) = xnode.Name
i += 1
Next
Return s
End Function

HTH
Steve

"vbmark" <no@email.com> wrote in message
news:Xn************************@199.45.49.11...
I have the follwing XML string:

<RecordSet>
<Row RowNumber="1">
<UserID>111</UserID>
<Phone>1234567890</Phone>
</Row>
<Row RowNumber="2">
<UserID>747</UserID>
<Phone>9876543210</Phone>
</Row>
</RecordSet>

A <Row> can have a variable number of elements in it.

How do I get a list of the elements? Such as in the
above case would be UserID and Phone?

My goal is to convert the XML into a Dataset.

Thanks!



Nov 21 '05 #5
Did it give you an error, or was the data not stored in the way you
wanted it?

Marcie

On Tue, 26 Apr 2005 20:25:12 GMT, vbmark <no@email.com> wrote:
I could not get it to work for me. I'm sure that I just wasn't doing
something right.

Marcie Jones <ma*********@yahoo.com> wrote in
news:oi********************************@4ax.com :
Hi Mark,
Any reason you can't just read the Xml directly into a DataSet, using
the .ReadXml() method?

Marcie

On Tue, 26 Apr 2005 19:36:59 GMT, vbmark <no@email.com> wrote:
I have the follwing XML string:

<RecordSet>
<Row RowNumber="1">
<UserID>111</UserID>
<Phone>1234567890</Phone>
</Row>
<Row RowNumber="2">
<UserID>747</UserID>
<Phone>9876543210</Phone>
</Row>
</RecordSet>

A <Row> can have a variable number of elements in it.

How do I get a list of the elements? Such as in the
above case would be UserID and Phone?

My goal is to convert the XML into a Dataset.

Thanks!



Nov 21 '05 #6
Opps! Sorry. You select that first thing. It's the DocumentElement of the
XmlDocument
Dim m_xmldoc as New XmlDocument
Dim m_root as XmlElement
m_xmldoc.Load(fileNameandPath)
m_root = m_xmldoc.DocumentElement
"vbmark" <no@email.com> wrote in message
news:Xn************************@199.45.49.11...
What's m_root?

"Steve Long" <St**********@NoSpam.com> wrote in news:#dnCXtpSFHA.3244
@TK2MSFTNGP15.phx.gbl:
Here's one way:

Public Function GetNodes(ByVal xpathExpression As String) As String()
Dim node As XmlNode = m_root.SelectSingleNode(xpathExpression)
If node Is Nothing Then Return Nothing
Dim nodelist As XmlNodeList = node.ChildNodes
Dim s(nodelist.Count - 1) As String
Dim i As Integer = 0
For Each xnode As XmlNode In nodelist
s(i) = xnode.Name
i += 1
Next
Return s
End Function

HTH
Steve

"vbmark" <no@email.com> wrote in message
news:Xn************************@199.45.49.11...
I have the follwing XML string:

<RecordSet>
<Row RowNumber="1">
<UserID>111</UserID>
<Phone>1234567890</Phone>
</Row>
<Row RowNumber="2">
<UserID>747</UserID>
<Phone>9876543210</Phone>
</Row>
</RecordSet>

A <Row> can have a variable number of elements in it.

How do I get a list of the elements? Such as in the
above case would be UserID and Phone?

My goal is to convert the XML into a Dataset.

Thanks!


Nov 21 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
1520
by: Alex | last post by:
Hello, I don't have sufficient experience with XSLT, and would really appreciate somebody's help in me giving ideas on solving a problem I have. Let's consider the following XML file: ...
6
1683
by: Affan Syed | last post by:
Hi, I am getting this weird problem. I know what i am doing is strange.. i am using C++ vectors and fopen, but for some reason if i used ofstream in the similar scenario it would give me errors....
5
4972
by: Patient Guy | last post by:
I have this in a document: <body onload="a_function(this);"> In an (external) script file, I define a_function() as follows: function a_function(obj) { // surprise errant coding here
16
9486
by: Bob Rock | last post by:
Hello, when serializing an array of elements of a class Classname using XmlSerializer.Serialize() I get an XML like the following: <?xml version="1.0"> <ArrayOfClassname> ....... ..........
6
6559
by: Carmine | last post by:
When I issue a db2 list db directory command, most of the node names are wrong. Is this a bug in Db2 v7 or is there something that I am missing? Thanx...
3
4316
by: avanti | last post by:
Hi, I have an application that has a tag hierarchy that is pulled from the database and displayed in a treeview. I want to enable the user to add nodes (tags) to this treeview at runtime and...
2
3911
by: naima.mans | last post by:
Hello, i want to select 2 following brothers nodes wich are one under another (one closed to another)... i have done one xslt file... but it's not really good.. for example: the xml file:...
0
3358
by: HP17 | last post by:
Hi all, I am a bit desperate already trying to display a XML file using XSLT. I create a table and use <xsl:for-each> to extract every element node. This is working fine. What I want now is so...
1
3491
by: Falcula | last post by:
Hello, I have a treeview control, when i select a item i navigate to url. But selected node is lost, it reset itself, loosing state. I post my code here. Thanks in advance. <script...
0
7105
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
6967
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
7132
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,...
1
6846
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...
1
4870
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4564
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3076
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
1381
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
266
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.