我正在尝试从edmx xml解析 m:MaxDataServiceVersion 的值,它的开头如下所示:
<edmx:Edmx Version="1.0">
<edmx:DataServices m:DataServiceVersion="1.0" m:MaxDataServiceVersion="3.0">
<Schema Namespace="NorthwindModel">
<EntityType Name="Category">
以下代码返回所需的元素
string nav = navigator.SelectSingleNode("//*[local-name() = 'DataServices']");
但是我所有获取属性值的尝试都没有成功。这是我尝试过的:
string nav = navigator.SelectSingleNode("//*[local-name() = 'DataServices']").GetAttribute("@{m}MaxDataServiceVersion", "");
nav = navigator.SelectSingleNode("//*[local-name() = 'DataServices']").GetAttribute("m:MaxDataServiceVersion", "");
nav = navigator.SelectSingleNode("//*[local-name() = 'DataServices']").GetAttribute("MaxDataServiceVersion", "");
nav = navigator.SelectSingleNode("//*[local-name() = 'DataServices']").GetAttribute("MaxDataServiceVersion", "m");
nav = navigator.SelectSingleNode("//*[local-name() = 'DataServices']").GetAttribute("MaxDataServiceVersion", "edmx:m");
运行以下代码
XPathNodeIterator nodes = navigator.Select("//*[local-name() = 'DataServices']");
while (nodes.MoveNext())
{
XPathNavigator navigator2 = nodes.Current.Clone();
navigator2.MoveToFirstAttribute();
Console.WriteLine("{0} = {1}", navigator2.Name, navigator2.Value);
while (navigator2.MoveToNextAttribute())
{
Console.WriteLine("{0} = {1}", navigator2.Name, navigator2.Value);
}
Console.WriteLine();
}
将输出两个属性
m:DataServiceVersion = 1.0
m:MaxDataServiceVersion = 3.0
但是我认为应该可以在不遍历所有这些的情况下获得所需的...
那么有没有办法在m:MaxDataServiceVersion
不循环的情况下获得价值?