powershell - Powershell "Cannot set "属性错误“因为只有字符串可以用作设置 XmlNode 属性的值

标签 powershell soap

我在向 XML 形式的 SOAP 调用分配值时遇到问题。该值在变量中定义,但 Powershell 不断返回此错误:

"Cannot set "Attribute" because only strings can be used as values to set XmlNode properties"

我的变量定义为字符串:[string]$AvidDisplayNameMinusTransfer

这是带有变量的 SOAP 调用:

$soap = [xml]@'

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:typ="http://avid.com/interplay/ws/assets/types">
   <soapenv:Header>
      <typ:UserCredentials>
         <typ:Username>***</typ:Username>
         <typ:Password>***</typ:Password>
      </typ:UserCredentials>
   </soapenv:Header>
   <soapenv:Body>
      <typ:Search>
         <typ:InterplayPathURI>interplay://AvidEng103/LTW</typ:InterplayPathURI>
         <typ:SearchGroup Operator="AND">
            <!--Zero or more repetitions:-->
            <typ:AttributeCondition Condition="EQUALS">
               <typ:Attribute Group="USER" Name="Display Name"></typ:Attribute>
            </typ:AttributeCondition>
         </typ:SearchGroup>
         <typ:ReturnAttributes>
            <typ:Attribute Group="SYSTEM" Name="MOB ID"></typ:Attribute>
         </typ:ReturnAttributes>
      </typ:Search>
   </soapenv:Body>
</soapenv:Envelope>

'@

$soap.Envelope.Body.Search.SearchGroup.AttributeCondition.Attribute = $AvidDisplayNameMinusTransfer

如果有人需要我的完整代码来提供更好的上下文,请告诉我。

最佳答案

使用innerText属性指定一个字符串作为标签的内容:

$soap.Envelope.Body.Search.SearchGroup.AttributeCondition.Attribute<b>.innerText</b> = $AvidDisplayNameMinusTransfer

结果:

PS C:\> <b>$soap.Envelope.Body.Search.SearchGroup.AttributeCondition.Attribute</b>

Group         Name               #text
-----         ----               -----
USER          Display Name       foo

关于powershell - Powershell "Cannot set "属性错误“因为只有字符串可以用作设置 XmlNode 属性的值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32574043/

相关文章:

python - 通过 Powershell 脚本运行 python 脚本

powershell - ConvertTo-SecureString 在不同的服务器上提供不同的体验

php - 库与 OpenSSL 和 PHP 5.3.3 冲突?

java - JAX-WS 和 Joda-Time?

powershell - 如何测试powershell中是否有事件的网络连接?

powershell - Post Build PowerShell 脚本不包括已安装的模块

regex - 使用Powershell将Markdown格式的文本解析为BBCode

php - 如何使用非默认内容类型调用 PHP Soap 1.1

node.js - 使用 Sabre SOAP API 检索航类信息时出错

magentosoapapiv2catalogProductInfo “Session expired. Try to relogin”错误