How to read CDATA in XML file with PowerShell?

puttputt picture puttputt · Aug 13, 2009 · Viewed 13.1k times · Source

I am having a difficult time reading an XML file with Cdata inside.

in $xmlsource

<list>
  <topic>
     <topicTitle>Test</topicTitle>
     <topicDetail><![CDATA[<br>randomHTMLhere</br>]]></topicDetail>
  </topic>
</list>

powershell

[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?

Answer

Peter Seale picture Peter Seale · Aug 13, 2009

$topic.topicDetail."#cdata-section"

or

$topic.topicDetail.InnerText