Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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.

like image 786
Ryan Jensen Avatar asked Feb 09 '23 01:02

Ryan Jensen


1 Answers

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
like image 138
Ansgar Wiechers Avatar answered May 18 '23 12:05

Ansgar Wiechers