How to read CDATA in XML file with PowerShell?

♀尐吖头ヾ 提交于 2019-12-08 15:04:52

问题


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?


回答1:


$topic.topicDetail."#cdata-section"

or

$topic.topicDetail.InnerText



来源:https://stackoverflow.com/questions/1274070/how-to-read-cdata-in-xml-file-with-powershell

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!