Solved

Problem querying xml file

Posted on 2010-11-13
3
420 Views
Last Modified: 2013-11-11
I am attempting to query the xml file to return the Tasks using the following code which is not returning anything! Is it possible to use linq to query an xml file of this structure?

Code:
  Dim doc As XDocument = XDocument.Load(XMLDOCFILEPATH)
            Dim qList = From xe In doc.XPathSelectElements("//Tasks") _
                    Select New With { _
                            .TaskId = xe.Attribute("TaskId").Value, _
                            .Question = xe.Attribute("Question").Value, _
                            .Result = xe.Element("Result").Value, _
                            .Comment = xe.Element("Comment").Value _
                            }
            Me.DataGridView1.DataSource = qList. engineereventVCAtwork.xml
0
Comment
Question by:JoeBo747
  • 2
3 Comments
 
LVL 62

Accepted Solution

by:
Fernando Soto earned 500 total points
Comment Utility
Hi JoeBo747;

Made some changes to your code. Also your XML document has a Namespace and you need to account for it in the query as shown below.

Fernando
Dim doc As XDocument = XDocument.Load(XMLDOCFILEPATH)



' You need to account for the Namespace in the document

Dim ns As XNamespace = "http://mycomp.co.uk/Sexton.xsd/v2"



Dim qList = From xe In doc.Descendants(ns + "Task") _

            Select New With { _

                    .TaskId = xe.Element(ns + "TaskId").Value, _

                    .Question = xe.Element(ns + "Question").Value, _

                    .Result = xe.Element(ns + "Result").Value, _

                    .Comment = xe.Element(ns + "Comment").Value _

                }



Me.DataGridView1.DataSource = qList.ToList

Open in new window

0
 
LVL 1

Author Closing Comment

by:JoeBo747
Comment Utility
Thanks Fernando thats great.
0
 
LVL 62

Expert Comment

by:Fernando Soto
Comment Utility
Not a problem, glad I was able to help.
0

Featured Post

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Flash (http://en.wikipedia.org/wiki/Adobe_Flash) has evolved over the years to where it has become a masterful tool for displaying content screen.  It has excellent layout placement, UI precision as well as rendering capabilities. This, along with t…
This article describes relatively difficult and non-obvious issues that are likely to arise when creating COM class in Visual Studio and deploying it by professional MSI-authoring tools. It is assumed that the reader is already familiar with the cla…
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

772 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

9 Experts available now in Live!

Get 1:1 Help Now