Solved

Query XML File

Posted on 2006-10-29
4
173 Views
Last Modified: 2012-05-05
Hi All,

I have an xml file that I would like to query.

The file has 3 "columns" lets just call them col1, col2, col3

I want to query for instance, col1 and return the value of col2.
The rows are unique, so returning more than 1 "record" or value will not occur.

I haven't done much with xml and would like a nice example if possible.

Thanks
0
Comment
Question by:nzfire
  • 2
4 Comments
 
LVL 39

Accepted Solution

by:
appari earned 500 total points
ID: 17831913
try something like this

xmlDS = New DataSet
xmlDS.ReadXml(XmlName)

if xmlDS isnot nothing andalso xmlDS.tables.count<>0 then
   dim dtTest as datatable = xmlDS.tables(0)
   dim drData as datarow() = dtTest.select(" col1 = '" & col1Value & "' ")
end if
0
 
LVL 12

Expert Comment

by:vb_jonas
ID: 17832198
... and then:

If drData.Length=1 then
  return drData(0)("col2")
Else
  ' not found or found more than 1
End If

0
 
LVL 12

Expert Comment

by:vb_jonas
ID: 17832224
if you like to you can use the compute method of the datatable:

returnvalue = dtTest.Compute("Sum(col2)","col1='" & col1filter & "'")

which will return the sum of col2 for records where col1=col1filter.

0
 
LVL 1

Author Comment

by:nzfire
ID: 17836898
Hi All,

Thanks for those posts. I was thinking along the lines of a dataset.

How about using an XPath query?

Which is faster? A dataset or reading through the xml nodes?

Thanks again for your help.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article explains how to create and use a custom WaterMark textbox class.  The custom WaterMark textbox class allows you to set the WaterMark Background Color and WaterMark text at design time.   IMAGE OF WATERMARKS STEPS Create VB …
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…

863 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now