[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

Problem querying xml file

Posted on 2010-11-13
3
Medium Priority
?
446 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
[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
3 Comments
 
LVL 64

Accepted Solution

by:
Fernando Soto earned 2000 total points
ID: 34127463
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
ID: 34127537
Thanks Fernando thats great.
0
 
LVL 64

Expert Comment

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

Featured Post

Learn Veeam advantages over legacy backup

Every day, more and more legacy backup customers switch to Veeam. Technologies designed for the client-server era cannot restore any IT service running in the hybrid cloud within seconds. Learn top Veeam advantages over legacy backup and get Veeam for the price of your renewal

Question has a verified solution.

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

Recently while returning home from work my wife (another .NET developer) was murmuring something. On further poking she said that she has been assigned a task where she has to serialize and deserialize objects and she is afraid of serialization. Wha…
More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
This course is ideal for IT System Administrators working with VMware vSphere and its associated products in their company infrastructure. This course teaches you how to install and maintain this virtualization technology to store data, prevent vuln…
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…

650 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