How do I get a list of child elements from XDocument object?

Posted by Nick on Stack Overflow See other posts from Stack Overflow or by Nick
Published on 2010-03-30T00:40:06Z Indexed on 2010/03/30 0:43 UTC
Read the original article Hit count: 459

Filed under:
|
|
|

Hello..

I am trying to get all of the "video" elements and their attributes from an XML file that looks like this:

<?xml version="1.0" encoding="utf-8" ?>
<videos>
  <video title="video1" path="videos\video1.wma"/>
  <video title="video2" path="videos\video2.wma"/>
  <video title="video3" path="videos\video3.wma"/>
</videos>

The following will only select the root node and all of the children. I would like to get all of the 'video' elements into the IEnumerable. Can someone tell me what I'm doing wrong?

 IEnumerable<XElement> elements = from xml in _xdoc.Descendants("videos")
                           select xml;

The above returns a collection with a length == 1. It contains the root element and all the children.

© Stack Overflow or respective owner

Related posts about linq-to-xml

Related posts about xdocument