2011-12-18 96 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