Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

LINQ to XML: how to get collection of all attributes from all elements

Tags:

linq-to-xml

I have some XML like this:

<Section xmlns=\"http:schemas.microsoft.com/winfx/2006/xaml/presentation\"> <Paragraph FontSize=\"12\" FontFamily=\"Arial\" Foreground=\"#FF000000\" FontWeight=\"Normal\" FontStyle=\"Normal\" FontStretch=\"Normal\" TextAlignment=\"Left\"> <Run FontWeight=\"Normal\" Text=\"space \" /> </Paragraph> </Section>

Is there a way to get a collection of all the FontWeight attributes, all the FontSize attributes, etc., regardless of the parent element?

like image 436
Number8 Avatar asked Dec 07 '25 03:12

Number8


1 Answers

Assuming you have XDocument doc = XDocument.Load("file.xml") you can get all attributes with doc.Descendants().Attributes() or all attributes of a certain name with e.g. doc.Descendants().Attributes("FontSize").

like image 59
Martin Honnen Avatar answered Dec 11 '25 09:12

Martin Honnen



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!