XmlPoke和唯一节点 [英] XmlPoke and unique nodes

查看:93
本文介绍了XmlPoke和唯一节点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用xmlpoke任务来更新VS Project文件(它是XML).在项目根目录中,有多个PropertyGroup节点,我试图选择第一个. XML看起来像这样

I am trying to use an xmlpoke task to update a VS Project File (which is XML). In the Project root, there are multiple PropertyGroup nodes, I am trying to select the first one. The XML looks like this

 <Project>
    <PropertyGroup>
    </PropertyGroup>
    <PropertyGroup>
    </PropertyGroup>
    <PropertyGroup>
    </PropertyGroup>
 </Project>

我正在使用//Project/PropertyGroup[1]的xpath来获取第一个PropertyGroup,但出现错误:给定//Project/PropertyGroup [1]的非唯一xpath".

I am using an xpath of //Project/PropertyGroup[1] to get the first PropertyGroup, but I get the error: "Non-unique xpath given //Project/PropertyGroup[1]".

edit:抱歉,我认为这没关系(但确实如此),Project有一个命名空间.我将带有正确xmlpoke的正确XML用作将来任何搜索者的答案.

edit: sorry, I didn't think it mattered (but it does), Project has a namespace. I put the correct XML with the correct xmlpoke as an answer for any future searchers.

推荐答案

好吧,我在上面简化了XML片段,如果没有的话,我想有人会弄清楚的.答案是,由于Project具有名称空间,因此必须像这样

Ok, I simplified the XML snippet above too much -- I think someone would have figured it out if I hadn't. The answer is that since Project has a namespace, it needs to be like this

   <xmlpoke file="project_file.csproj" value="v4.0" xpath="//x:Project/x:PropertyGroup[1]/x:TargetFrameworkVersion">
    <namespaces>
      <namespace prefix="x" uri="http://schemas.microsoft.com/developer/msbuild/2003" />
    </namespaces>
   </xmlpoke>

作为参考,Project标记如下所示:

For reference, the Project tag looks like this:

  <Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" DefaultTargets="Build">

这篇关于XmlPoke和唯一节点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆