• <small id='cNvOM'></small><noframes id='cNvOM'>

      <bdo id='cNvOM'></bdo><ul id='cNvOM'></ul>
    <i id='cNvOM'><tr id='cNvOM'><dt id='cNvOM'><q id='cNvOM'><span id='cNvOM'><b id='cNvOM'><form id='cNvOM'><ins id='cNvOM'></ins><ul id='cNvOM'></ul><sub id='cNvOM'></sub></form><legend id='cNvOM'></legend><bdo id='cNvOM'><pre id='cNvOM'><center id='cNvOM'></center></pre></bdo></b><th id='cNvOM'></th></span></q></dt></tr></i><div id='cNvOM'><tfoot id='cNvOM'></tfoot><dl id='cNvOM'><fieldset id='cNvOM'></fieldset></dl></div>

      1. <tfoot id='cNvOM'></tfoot>

      2. <legend id='cNvOM'><style id='cNvOM'><dir id='cNvOM'><q id='cNvOM'></q></dir></style></legend>

        使用 XElement 查询命名空间中的节点

        using XElement to query for a node in namespace(使用 XElement 查询命名空间中的节点)
        <tfoot id='p1ctO'></tfoot>

            <tbody id='p1ctO'></tbody>

              <bdo id='p1ctO'></bdo><ul id='p1ctO'></ul>
              • <i id='p1ctO'><tr id='p1ctO'><dt id='p1ctO'><q id='p1ctO'><span id='p1ctO'><b id='p1ctO'><form id='p1ctO'><ins id='p1ctO'></ins><ul id='p1ctO'></ul><sub id='p1ctO'></sub></form><legend id='p1ctO'></legend><bdo id='p1ctO'><pre id='p1ctO'><center id='p1ctO'></center></pre></bdo></b><th id='p1ctO'></th></span></q></dt></tr></i><div id='p1ctO'><tfoot id='p1ctO'></tfoot><dl id='p1ctO'><fieldset id='p1ctO'></fieldset></dl></div>

                <legend id='p1ctO'><style id='p1ctO'><dir id='p1ctO'><q id='p1ctO'></q></dir></style></legend>

              • <small id='p1ctO'></small><noframes id='p1ctO'>

                  本文介绍了使用 XElement 查询命名空间中的节点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我正在尝试从看起来像这样的 csproj 文件中提取一个节点,但无法让它工作 - 大概是因为命名空间声明.

                  i'm trying to pull out a node from a csproj file that looks like this, but can't get it to work - presumably because of the namespace declaration.

                  <?xml version="1.0" encoding="utf-8"?>
                  <Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" DefaultTargets="Build">
                        <PropertyGroup>
                            <RegisterForComInterop>true</RegisterForComInterop>
                  

                  这失败得很惨:

                  XDocument cpo = XDocument.Load(file);
                  XmlNamespaceManager nsm = new XmlNamespaceManager(new NameTable());
                  nsm.AddNamespace("x", "http://schemas.microsoft.com/developer/msbuild/200");
                  IEnumerable<XElement> list3 = cpo.XPathSelectElements("//x:RegisterForComInterop[.='true']", nsm);
                  

                  请问大家有什么想法吗?

                  Anyone any ideas please?

                  谢谢.

                  推荐答案

                  你真的要为此使用 XPath 吗?在 LINQ to XML 中使用命名空间真的很容易:

                  Do you really want to use XPath for this? It's really easy to use namespaces within LINQ to XML:

                  XDocument cpo = XDocument.Load(file);
                  XNamespace x = "http://schemas.microsoft.com/developer/msbuild/2003";
                  var elements = cpo.Descendants(x + "RegisterForComInterop")
                                    .Where(x => (string) x == "true");
                  

                  或者,如果您绝对确信每个 RegisterForComInterop 都将具有适当的布尔值,您可以使用 explicitXElementbool 转换:

                  or if you're absolutely convinced that every RegisterForComInterop will have an appropriate Boolean value you can use the explicit XElement to bool conversion:

                  XDocument cpo = XDocument.Load(file);
                  XNamespace x = "http://schemas.microsoft.com/developer/msbuild/2003";
                  var elements = cpo.Descendants(x + "RegisterForComInterop")
                                    .Where(x => (bool) x);
                  

                  如果涉及命名空间,我个人通常会选择这条路线而不是 XPath尤其是.

                  Personally I would usually go this route rather than XPath especially if namespaces are involved.

                  这篇关于使用 XElement 查询命名空间中的节点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  C# namespace alias - what#39;s the point?(C# 命名空间别名 - 有什么意义?)
                  Using Xpath With Default Namespace in C#(在 C# 中使用具有默认命名空间的 Xpath)
                  Generating an EDMX from a DB2 Database(从 DB2 数据库生成 EDMX)
                  IBM .NET Data Provider Connection String issue with Library List(库列表的 IBM .NET 数据提供程序连接字符串问题)
                  .NET DB2 OLEDB pre-requisites(.NET DB2 OLEDB 先决条件)
                  Referring to Code in IBM.Data.DB2 makes that Assembly Unavailable to the rest of my Solution(引用 IBM.Data.DB2 中的代码使该程序集对我的解决方案的其余部分不可用)

                        <i id='yWEXR'><tr id='yWEXR'><dt id='yWEXR'><q id='yWEXR'><span id='yWEXR'><b id='yWEXR'><form id='yWEXR'><ins id='yWEXR'></ins><ul id='yWEXR'></ul><sub id='yWEXR'></sub></form><legend id='yWEXR'></legend><bdo id='yWEXR'><pre id='yWEXR'><center id='yWEXR'></center></pre></bdo></b><th id='yWEXR'></th></span></q></dt></tr></i><div id='yWEXR'><tfoot id='yWEXR'></tfoot><dl id='yWEXR'><fieldset id='yWEXR'></fieldset></dl></div>
                          <tbody id='yWEXR'></tbody>
                      1. <small id='yWEXR'></small><noframes id='yWEXR'>

                        <tfoot id='yWEXR'></tfoot>

                          • <bdo id='yWEXR'></bdo><ul id='yWEXR'></ul>
                            <legend id='yWEXR'><style id='yWEXR'><dir id='yWEXR'><q id='yWEXR'></q></dir></style></legend>