您可以通過XML這樣對LINQ的波紋管:
XDocument xmlDoc = XDocument.Load("a.xml");
var nodeAttrs = xmlDoc.Descendants().Select(x => x.Attributes());
foreach (var attrs in nodeAttrs)
{
foreach (var attr in attrs)
Console.WriteLine("Name: {0}, Value :{1}", attr.Name ,attr.Value);
}
輸出如下爲您的XML:
Name: name, Value :Student
Name: name, Value :studentinfo
Name: name, Value :notes
Name: name, Value :ss
Name: type, Value :textArea
Name: x, Value :xxx
Name: name, Value :Teacher
Name: name, Value :doctor
編輯:如果你有這代表你的XML字符串,你可以做
var xmlString = "<Permission> <CP name=\"Student\"> <tab name=\"studentinfo\"></tab><tab name=\"notes\"><groupbox name=\"ss\"><field type=\"textArea\" x=\"xxx\" /></groupbox></tab></CP><CP name=\"Teacher\"></CP><CP name=\"doctor\"></CP></Permission>";
byte[] byteArray = Encoding.ASCII.GetBytes(xmlString);
MemoryStream stream = new MemoryStream(byteArray);
然後
var xmlDoc = XDocument.Load(stream);
你有一個示例架構? – Iain 2010-11-21 10:08:29
更新......... – salman 2010-11-21 10:11:39
xml代碼不是在這裏apearing,但你可以得到一個想法 – salman 2010-11-21 10:13:21