LInq and XML RRS feed

  • Question

  • I have the following XML form which is coming back form Amazon S3 bucket list and I want to use linq to query the Bucket names but because it the second level down it seems to be failing to find the Name attribute 

    <?xml version="1.0" encoding="UTF-8"?>
    <ListAllMyBucketsResult xmlns="">

    the code i have is 

                XDocument xdoc = XDocument.Parse(XMLFeed) ;
                var query = from t in xdoc.Descendants("Name")
                            select t.Value;

    but this fails to find the anything?

    Regards Dagz

    Friday, August 4, 2017 4:24 PM


  • I think that the behavior is caused by the namespace. Remove temporarily the xmlns attribute and your code will work.

    You will find several solutions to make it work with namespaces. Try this too:

    var query = from t in xdoc.Descendants( "{}Name" )
                select t.Value;

    • Marked as answer by Dagz Monday, August 7, 2017 7:57 AM
    Monday, August 7, 2017 4:42 AM