?
Solved

Problem querying xml file

Posted on 2010-11-13
3
Medium Priority
?
442 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 63

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 63

Expert Comment

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

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

This document covers how to connect to SQL Server and browse its contents.  It is meant for those new to Visual Studio and/or working with Microsoft SQL Server.  It is not a guide to building SQL Server database connections in your code.  This is mo…
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…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Suggested Courses

801 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