我在向 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/