正确使用msbuild xmlpoke的方法

时间:2013-09-20 09:19:59

标签: xpath msbuild namespaces prefix xmlpoke

如果元素值匹配,我正在尝试设置元素的值 “ABB Automation Builder Platform.abpkg”

我的脚本使用xmlpoke,如下所示:

<XmlPoke 
                Namespaces="&lt;Namespace Prefix='x'  Uri='http://www150.abb.com/spaces/DAE-1/ProdDev/Shared%20Documents/40%20DAE%20Installer/Design/XML%20Descriptions/DAEInstaller_Description_StyleSheet' &gt;"
                Query="x:ProductUpdate/x:Packages/x:Package[x:FileName='ABB Automation Builder Platform.abpkg']/x:FileHash"
                XmlInputPath="Output\update.manifest"
                Value="Ajay Vishwakarma"/>

我想修改的xml如下:

<?xml version="1.0" encoding="utf-8"?>
<ProductUpdate xmlns="http://www150.abb.com/spaces/DAE-1/ProdDev/Shared%20Documents/40%20DAE%20Installer/Design/XML%20Descriptions/DAEInstaller_Description_StyleSheet">
  <Strings>
    <Text id="1">
      <Neutral>ABB Automation Builder 1.0 \nService Release 1</Neutral>
      <Localized culture="en">ABB Automation Builder 1.0 \nService Release 1</Localized>
      <Localized culture="de">ABB Automation Builder 1.0 \nService Release 1</Localized>
      <Localized culture="fr">ABB Automation Builder 1.0 \nService Release 1</Localized>
      <Localized culture="es">ABB Automation Builder 1.0 \nService Release 1</Localized>
      <Localized culture="zh">ABB Automation Builder 1.0 \nService Release 1</Localized>
    </Text>
    <Text id="2">
      <Neutral>Information\ABB Automation Builder Upate Package V1_0_1Description_en.htm</Neutral>
      <Localized culture="en">Information\ABB Automation Builder Upate Package V1_0_1Description_en.htm</Localized>
      <Localized culture="de">Information\ABB Automation Builder Upate Package V1_0_1Description_de.htm</Localized>
      <Localized culture="fr">Information\ABB Automation Builder Upate Package V1_0_1Description_fr.htm</Localized>
      <Localized culture="es">Information\ABB Automation Builder Upate Package V1_0_1Description_es.htm</Localized>
      <Localized culture="zh">Information\ABB Automation Builder Upate Package V1_0_1Description_zh.htm</Localized>
    </Text>
  </Strings>
  <ReleaseType>ServicePack</ReleaseType>
  <ProductName>$1</ProductName>
  <Version>1.0.1</Version>
  <Description>$2</Description>
  <License>
    <Name>$3</Name>
    <ID>45668677876463</ID>
    <Description>$4</Description>
    <Version>1.0.1</Version>
    <DescriptionVersion>$5</DescriptionVersion>
    <DescriptionTypeVersion>1.0.0</DescriptionTypeVersion>
    <ToAccept>true</ToAccept>
  </License>
  <Copyright>$6</Copyright>
  <MinimumRequiredVersion>1.0.0</MinimumRequiredVersion>
  <Packages>
    <Package>
      <Name>ABB Automation Builder Platform Update Package</Name>
      <Description>ABB Automation Builder Platform Update Package</Description>
      <FileName>ABB Automation Builder Platform.abpkg</FileName>
      <FileHash>AjayVishwakarma</FileHash>
      <FileDownload>
      </FileDownload>
      <InstallerData>
        <Component>
          <Name>ABB Automation Builder Package Manager</Name>
          <ID>{F5B05B3F-9FA5-476E-BDD3-DB1397CABF4C}</ID>
          <Version>1.0.1.0</Version>
          <InstallAlways>true</InstallAlways>
        </Component>
      </InstallerData>
    </Package>
    <Package>
      <Name>PLC AC500 Update Package</Name>
      <Description>PLC AC500 Update Package</Description>
      <FileName>PLC - AC500.abpkg</FileName>
      <FileHash>8652d588d4c1fe70e0e06a9cf3e09193</FileHash>
      <FileDownload>
      </FileDownload>
      <InstallerData>
        <Component>
          <Name>Codesys</Name>
          <ID>{F8A33E2A-5B6A-474B-8ED2-293B4982D4E6}</ID>
          <Version>2.3.9.41</Version>
        </Component>
        <Component>
          <Name>Target Support Package</Name>
          <ID>{CC764263-BEF5-4060-AA49-0366AB2E868B}</ID>
          <Version>1.0.1.0</Version>
        </Component>
        <Component>
          <Name>Control Builder Plus documentation</Name>
          <ID>{484D63DB-1EB6-4F4F-851F-7F7D7D34A396}</ID>
          <Version>1.0.1.0</Version>
        </Component>
      </InstallerData>
    </Package>    
  </Packages>
</ProductUpdate>

XmlPoke任务无法更新元素值并给出消息“Made 0 replacement(s)”。 我也尝试传递像

这样的查询

Query =“// x:ProductUpdate / x:Packages / x:Package [x:FileName ='ABB Automation Builder Platform.abpkg'] / x:FileHash”或者 Query =“.// x:ProductUpdate / Packages / Package [FileName ='ABB Automation Builder Platform.abpkg'] / FileHash”

我想知道我做错了吗? 请注意,我不想在我的xml文档中对命名空间进行任何更改。

2 个答案:

答案 0 :(得分:1)

你不是疯了。

命名空间中原始xml文档中的(十六进制编码)空格正在抛弃它。

我没有答案。

但这是一个建议。

我总是使用XmlPeek,然后“建立”查询。

<XmlPeek Namespaces="&lt;Namespace Prefix='peanut' Uri='http://www150.abb.com/spaces/DAE-1/ProdDev/Shared%20Documents/40%20DAE%20Installer/Design/XML%20Descriptions/DAEInstaller_Description_StyleSheet'/&gt;"
     XmlInputPath=".\MyXmlFile.xml" 
     Query="//peanut:ProductUpdate">
    <Output TaskParameter="Result" ItemName="Peeked" />
</XmlPeek>


<Message Text="@(Peeked)"/>

(上面是XmlPeek,我有顶级查询“// ProductUpdate”。 Message @(Peeked)将显示那里的xml片段。 然后我可以建立查询并查看结果....并根据需要进行调整。 )

无论如何,回到问题:

所以上面的内容将 IF 你将原来的Xml更改为

<ProductUpdate xmlns="http://www150.abb.com/spaces/DAE-1/ProdDev/Shared Documents/40 DAE Installer/Design/XML Descriptions/DAEInstaller_Description_StyleSheet">
  <Strings>

但是原始的Xml带有空格的十六进制值......以上都行不通。 :(

反正。臭死了。它几乎就像命名空间(在XmlPeek(或Poke)中需要“双重编码”或其他东西。

对不起,我给了大学试试。

答案 1 :(得分:0)

我认为您需要创建一个有效的Namespace元素。你所拥有的是开始标记,而不是自闭元素。 而不是:

<Namespace Prefix='x'  
     Uri='http://www150.abb.com/spaces/..../DAEInstaller_Description_StyleSheet'>

你需要:

<Namespace Prefix='x'  
     Uri='http://www150.abb.com/spaces/..../DAEInstaller_Description_StyleSheet'/>