【问题标题】:Correct way of using msbuild xmlpoke使用 msbuild xmlpoke 的正确方法
【发布时间】:2013-09-20 09:19:59
【问题描述】:

如果元素值匹配,我正在尝试设置元素的值 "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 任务无法更新元素值并给出消息“进行 0 次替换”。 我也尝试过像

这样传递查询

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 文档中的命名空间进行任何更改。

【问题讨论】:

    标签: xpath msbuild namespaces prefix xmlpoke


    【解决方案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 片段。 然后我可以建立查询并查看结果....并根据需要进行调整。 )

    不管怎样,回到问题:

    所以上面的方法会起作用如果你把原来的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)中需要“双十六进制编码”或其他东西。

    对不起,我在大学里试过了。

    【讨论】:

      【解决方案2】:

      我认为您需要创建一个有效的命名空间元素。您拥有的是开始标签,而不是自封闭元素。 而不是:

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

      你需要:

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

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2017-06-11
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2023-03-18
        • 2015-12-17
        • 2012-02-23
        • 2013-01-09
        相关资源
        最近更新 更多