?
Solved

Query XML File

Posted on 2006-10-29
4
Medium Priority
?
183 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 2000 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

It’s quite interesting for me as I worked with Excel using vb.net for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
Are you ready to place your question in front of subject-matter experts for more timely responses? With the release of Priority Question, Premium Members, Team Accounts and Qualified Experts can now identify the emergent level of their issue, signal…
Screencast - Getting to Know the Pipeline
Suggested Courses

864 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