PowerShell: How to add XmlElement to a non-root element

Posted by Ariel on Stack Overflow See other posts from Stack Overflow or by Ariel
Published on 2010-06-14T22:54:59Z Indexed on 2010/06/14 23:02 UTC
Read the original article Hit count: 174

Filed under:
|

I'm having trouble adding an XmlElement to a non-root element in PowerShell.

Basically, given this xml:

<clubs>
        <club name="boca" position="1">
                <field>bombonera</field>
                <field>bombonerita</field>
        </club>
        <club name="racing" position="19">
                <field>cilindro</field>
        </club>
</clubs>

I create an element,

$new = $clubs.CreateElement("Barracas")

When I try to add this element to a non-root node i.e.

$clubs.clubs.club += $new

I get

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

What am I missing? Thanks in advance.

© Stack Overflow or respective owner

Related posts about Xml

Related posts about powershell