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

坚强是说给别人听的谎言 提交于 2019-12-11 03:39:21

问题


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?


回答1:


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").



来源:https://stackoverflow.com/questions/8551916/linq-to-xml-how-to-get-collection-of-all-attributes-from-all-elements

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!