Friday, August 26, 2011

Query for all XML Attributes

I needed all of the attributes contained in an XML document. It must be independant of namespaces.




//query for all of the attributes that should also be parsed and added
var els = ((from a in doc.Root.DescendantsAndSelf()
let count = a.Attributes().Select(ns => !ns.IsNamespaceDeclaration).Count()
where count > 0
select a).Attributes().Where(ns => !ns.IsNamespaceDeclaration)).ToList();



0 comments: