【问题标题】:Why won't this XPath query work on an .edmx file?为什么此 XPath 查询不适用于 .edmx 文件?
【发布时间】:2009-07-24 15:20:29
【问题描述】:

我正在尝试获取 EDMX 文件中的 EntityTypes 列表,但以下查询未返回任何结果:

XmlDocument edmxFile = new XmlDocument();
edmxFile.Load(args[0]);

XmlNamespaceManager nsMan = new XmlNamespaceManager(edmxFile.NameTable);
nsMan.AddNamespace("edmx", "http://schemas.microsoft.com/ado/2007/06/edmx");
nsMan.AddNamespace("s", "http://schemas.microsoft.com/ado/2007/06/edm/ssdl");
nsMan.AddNamespace("e", "http://schemas.microsoft.com/ado/2007/06/edm");
nsMan.AddNamespace("u", "urn:schemas-microsoft-com:windows:storage:mapping:SC");


XmlNodeList entityTypes =  edmxFile.DocumentElement.SelectNodes("//EntityType", nsMan); //Returns 0 nodes
XmlNodeList entityTypes =  edmxFile.SelectNodes("//EntityType"); //Returns 0 nodes also

为什么 XPath 在这里不起作用?

【问题讨论】:

    标签: c# xml xpath


    【解决方案1】:

    已经有一段时间了,但我认为您在调用这些方法时需要 "//s:EntityType"

    【讨论】:

    • 这没有成功,其他命名空间也没有
    • 我自己试了一下,它成功了——我唯一需要做的修改是我的 ssdl (s:) 命名空间 URI,即http://schemas.microsoft.com/ado/2006/04/edm/ssdl。我假设您使用的是 EF4,这就是为什么您有不同的 URI?
    • 我用的是VS2008 SP1,用了你做的架构后,成功了,谢谢!
    猜你喜欢
    • 2019-12-05
    • 1970-01-01
    • 2013-12-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-12-27
    • 2020-05-12
    • 2021-01-01
    相关资源
    最近更新 更多