【问题标题】:How to read CDATA in XML file with PowerShell?如何使用 PowerShell 读取 XML 文件中的 CDATA?
【发布时间】:2010-11-19 10:22:45
【问题描述】:

我很难读取包含 Cdata 的 XML 文件。

在 $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 将为 null 而 $topic.topicTitle 不会。有什么想法吗?

【问题讨论】:

    标签: xml powershell cdata


    【解决方案1】:

    $topic.topicDetail."#cdata-section"

    $topic.topicDetail.InnerText

    【讨论】:

    • 谢谢!然后我使用 .get_FirstChild().get_Data() 来访问它。
    • 不错。请注意,您也可以像这样设置 CDATA:$topic.topicDetail."#cdata-section" = "foo" ... $xml.Save($path)
    猜你喜欢
    • 2017-03-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-01-07
    • 2010-12-21
    • 1970-01-01
    • 2014-01-18
    • 1970-01-01
    相关资源
    最近更新 更多