7

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.

0

2 Answers 2

8

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
Sign up to request clarification or add additional context in comments.

Comments

5

This error is silly in my opinion because the variable is a string. However, if you put quotes around the variable name, it works. Using innerhtml requires editing the entire node above as the attribute doesn't have an innerhtml property. The attribute itself has a get/set method so should work.

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.