?
Solved

Find node in XML using Linq

Posted on 2009-12-20
4
Medium Priority
?
261 Views
Last Modified: 2013-11-26
Hi to all,

I included a sample XML document that I am using. I need to be able to find the following in the XML:
<w:bookmarkStart w:id="0" w:name="testingTOCbookmark" />
Using LINQ.

I am using Visual Basic and it is a WPF Visual Studio 2008 Application.

Any help would be appreciated.

Thanks
Sample.xml
0
Comment
Question by:ALawrence007
  • 3
4 Comments
 
LVL 48

Expert Comment

by:jpaulino
ID: 26092255
I think you can use XML Literals in WPF!
Something like this:

        Dim doc = XDocument.Load("l:\sample.xml")
        Dim elem = doc...<w:bookmarkStart>.Where(Function(f) f.@w:id = "0").FirstOrDefault()
        Debug.WriteLine(elem.@w:name)

Open in new window

0
 
LVL 48

Accepted Solution

by:
jpaulino earned 2000 total points
ID: 26092264
Opps!
"Find node in XML using Linq"
Try this way instead:

        Dim result = From element As XElement In doc...<w:bookmarkStart> Where element.@w:id = "0"
        For Each r As XElement In result
            Debug.WriteLine(r.@w:name)
        Next

Open in new window

0
 

Author Closing Comment

by:ALawrence007
ID: 31668264
Worked perfect.
Thanks jpaulino!!
0
 
LVL 48

Expert Comment

by:jpaulino
ID: 26092967
Glad I could help!
0

Featured Post

[Webinar] Cloud and Mobile-First Strategy

Maybe you’ve fully adopted the cloud since the beginning. Or maybe you started with on-prem resources but are pursuing a “cloud and mobile first” strategy. Getting to that end state has its challenges. Discover how to build out a 100% cloud and mobile IT strategy in this webinar.

Question has a verified solution.

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

It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Hello there! As a developer I have modified and refactored the unit tests which was written by fellow developers in the past. On the course, I have gone through various misconceptions and technical challenges when it comes to implementation. I would…
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…
With just a little bit of  SQL and VBA, many doors open to cool things like synchronize a list box to display data relevant to other information on a form.  If you have never written code or looked at an SQL statement before, no problem! ...  give i…
Suggested Courses

864 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