2011-12-18 74 views
1

获得所有属性的集合,我有一些这样的XML:的LINQ to XML:如何从所有元素

<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> 

有没有办法让所有的fontWeight设置属性的集合,所有的字号属性,等等,无论父母的元素?

回答

2

假设你有XDocument doc = XDocument.Load("file.xml")你可以得到doc.Descendants().Attributes()所有属性或特定名称使用如的所有属性doc.Descendants().Attributes("FontSize")

+0

谢谢,但我没有一个文件,而是从丰富的文本框中输入一个字符串。 – Number8 2011-12-18 18:30:12

+0

明白了 - 使用Document.Parse()。这是我正在寻找的,谢谢。 – Number8 2011-12-18 19:05:03