如何使用PowerShell读取XML文件中的CDATA? [英] How to read CDATA in XML file with PowerShell?

查看:152
本文介绍了如何使用PowerShell读取XML文件中的CDATA?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在读取带有Cdata的XML文件时遇到了困难。

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>


powershell


[xml]$xml = get-content $xmlsource    

foreach ($topic in $xml.list) {
    $topic.topicTitle
    $topic.topicDetail
}

$ topic.topicDetail将为空,而$ topic.topicTitle将不为空。有想法吗?

$topic.topicDetail will be null while $topic.topicTitle will not be. Any ideas?

推荐答案

$ topic.topicDetail。#cdata-section

$ topic.topicDetail.InnerText

这篇关于如何使用PowerShell读取XML文件中的CDATA?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆