Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Query XML File

Posted on 2006-10-29
4
Medium Priority
?
181 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

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 …
Article by: jpaulino
XML Literals are a great way to handle XML files and the community doesn’t use it as much as it should.  An XML Literal is like a String (http://msdn.microsoft.com/en-us/library/system.string.aspx) Literal, only instead of starting and ending with w…
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…
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…
Suggested Courses

618 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