I'm having an issue with assigning a value to an SOAP call that's an XML. The value is defined in a variable, but Powershell keeps returning this error:
"Cannot set "Attribute" because only strings can be used as values to set XmlNode properties"
My variable is defined as a string: [string]$AvidDisplayNameMinusTransfer
Here's the SOAP Call with the variable:
$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
Let me know if anyone needs my entire code to give better context.
Use the innerText property to assign a string as the content of the tag:
$soap.Envelope.Body.Search.SearchGroup.AttributeCondition.Attribute.innerText = $AvidDisplayNameMinusTransfer
Result:
PS C:\> $soap.Envelope.Body.Search.SearchGroup.AttributeCondition.Attribute
Group         Name               #text
-----         ----               -----
USER          Display Name       foo
                        If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With