I am having a difficult time reading an XML file with Cdata inside.
<list>
<topic>
<topicTitle>Test</topicTitle>
<topicDetail><![CDATA[<br>randomHTMLhere</br>]]></topicDetail>
</topic>
</list>
[xml]$xml = get-content $xmlsource
foreach ($topic in $xml.list) {
$topic.topicTitle
$topic.topicDetail
}
$topic.topicDetail will be null while $topic.topicTitle will not be. Any ideas?
Syntax. CDATA End section − CDATA section ends with ]]> delimiter. CData section − Characters between these two enclosures are interpreted as characters, and not as markup. This section may contain markup characters (<, >, and &), but they are ignored by the XML processor.
PowerShell and Reading XML filesPowerShell provides an easy way to read XML files, manipulate them and finally to save them back to disk without writing a lot of code or knowing XPath. PowerShell does this by providing the user dot notation to signify each node in the XML document.
A CDATA section is used to mark a section of an XML document, so that the XML parser interprets it only as character data, and not as markup. It comes handy when one XML data need to be embedded within another XML document.
No, The markup denoting a CDATA Section is not permitted as the value of an attribute.
$topic.topicDetail."#cdata-section"
or
$topic.topicDetail.InnerText
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