william007
william007

Reputation: 18547

get all elements contain attributes from a namespace

I wish to get all elements that contain attributes from namespace http://www.my.com/

The code:

   IEnumerable<XElement> list1 =
                    from el in RootElement.DescendantsAndSelf()
                    //where it contains attributes from http://www.my.com/ - how?
                    select el;

Upvotes: 1

Views: 265

Answers (1)

Sergey Berezovskiy
Sergey Berezovskiy

Reputation: 236318

Verify namespace part of attribute name:

XNamespace my = "http://www.my.com/";
IEnumerable<XElement> list1 =
        from el in xdoc.Root.DescendantsAndSelf()
        where el.Attributes().Any(attr => attr.Name.Namespace == my)
        select el;

Upvotes: 2

Related Questions