BillyMadison
BillyMadison

Reputation: 93

Adding CData to XML code using Powershell

I am trying to create an XML document using Powershell. I am using System.XML.XMLTextWriter to create my document. I have searched all over looking for an answer and can't find it.

Here's what I have right now:

$variable = "my text"
$xmlWriter.WriteStartElement('Legal')
$xmlWriter.WriteStartElement("heading")
$XmlWriter.WriteAttributeString("![CDATA[]]",$Variable)

I would like the end result to look like:

 <Legal>
        <heading>
            <![CDATA[ $Variable ]]>
        </heading>
    </Legal>

Upvotes: 1

Views: 945

Answers (1)

BillyMadison
BillyMadison

Reputation: 93

$XmlWriter.WriteCData($Variable)

Upvotes: 0

Related Questions