Solved

Query XML File

Posted on 2006-10-29
4
174 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

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

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

Suggested Solutions

A while ago, I was working on a Windows Forms application and I needed a special label control with reflection (glass) effect to show some titles in a stylish way. I've always enjoyed working with graphics, but it's never too clever to re-invent …
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…
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…

813 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

14 Experts available now in Live!

Get 1:1 Help Now