XML:
<servers ver="1" namespace="RWT.Direct.Processors.Public.ROCTP">
<procedures>
<procedure name="Func1" returnType="">
<params>
<param name="p1" type="int" />
<param name="p2" type="int" keyword="out" />
</params>
</procedure>
<procedure name="Func2" returnType="int">
<params>
<param name="x" type="int" />
</params>
</procedure>
</procedures>
</servers>
我的代码:
FileStream fs = new FileStream(@"D:\DIRECT\bin\base\Servers\Test.xml", FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
StreamReader sr = new StreamReader(fs);
var doc = XDocument.Parse(sr.ReadToEnd());
List<Procedure> procedures = (from _api in doc.Element("servers").Descendants("procedures")
select new Procedure
{
Name = _api.Element("procedure").Attribute("name").Value,
ReturnType = _api.Element("procedure").Attribute("returnType").Value
}).ToList();
foreach (var item in procedures)
{
Console.WriteLine(item.Name + " " + item.ReturnType);
}
我只得到“Func1”回来。