阅读CDATA标记值

问题描述:

如何读取从XML CDATA标签信息,不需要任何额外的信息阅读CDATA标记值

的test.xml

<EncodingKeys> 
    <Streaming> 
     <![CDATA[54G91A8?s7^F97C]Fyj*8&kR2eU+HNg!]]> 
    </Streaming> 
    <Uploads> 
     <![CDATA[&^%&^*vsfgsdfEw#[email protected]!F2]]> 
    </Uploads> 
</EncodingKeys> 

test.sh

Streamingkey="$(echo "cat /EncodingKeys/Streaming/text()" | xmllint --nocdata --shell test.xml | sed '1d;$d')" 
Uploadskey="$(echo "cat /EncodingKeys/Uploads/text()" | xmllint --nocdata --shell test.xml | sed '1d;$d')" 

echo $Streamingkey 
echo $Uploadskey 

实际输出:

54G91A8?s7^F97C]Fyj*8&amp;kR2eU+HNg! 
&amp;^%&amp;^*vsfgsdfEw#[email protected]!F2 

预期输出:

54G91A8?s7^F97C]Fyj*8&kR2eU+HNg! 
&^%&^*vsfgsdfEw#[email protected]!F2 

为什么我代替&越来越&amp;。我还可以看到更多的id变量。

有人能帮我解决这个问题吗?

使用xml_grep!

准备测试文件

$cat test.xml 
    <EncodingKeys> 
     <Streaming> 
      <![CDATA[54G91A8?s7^F97C]Fyj*8&kR2eU+HNg!]]> 
     </Streaming> 
     <Uploads> 
      <![CDATA[&^%&^*vsfgsdfEw#[email protected]!F2]]> 
     </Uploads> 
    </EncodingKeys> 

为 '流' 使用

$ xml_grep --text_only 'Streaming' test.xml 

得到

54G91A8?s7^F97C]Fyj*8&kR2eU+HNg! 

为 '上传的' 使用

$ xml_grep --text_only 'Uploads' test.xml 

得到

&^%&^*vsfgsdfEw#[email protected]!F2