Solved

Query XML File

Posted on 2006-10-29
4
172 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
Comment Utility
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
Comment Utility
... 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
Comment Utility
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
Comment Utility
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

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

This tutorial demonstrates one way to create an application that runs without any Forms but still has a GUI presence via an Icon in the System Tray. The magic lies in Inheriting from the ApplicationContext Class and passing that to Application.Ru…
1.0 - Introduction Converting Visual Basic 6.0 (VB6) to Visual Basic 2008+ (VB.NET). If ever there was a subject full of murkiness and bad decisions, it is this one!   The first problem seems to be that people considering this task of converting…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

744 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

12 Experts available now in Live!

Get 1:1 Help Now