2016-07-28 13 views
3

Wie CDATA-Tag-Informationen aus XML ohne zusätzliche InformationenLese CDATA-Tag-Wert von XML ohne zusätzliche Informationen in Shell-Skript mit xmllint

test.xml

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

test.sh

lesen
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 

tatsächliche Ausgabe:

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

erwartete Ausgabe:

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

warum ich &amp; anstelle von & bin immer. und ich kann Längen ID Variablen auch mehr sehen.

Könnte jemand mir dabei helfen.

Antwort

1

Verwenden Sie xml_grep!

Bereiten Sie eine Testdatei

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

Für den Einsatz 'Streaming'

$ xml_grep --text_only 'Streaming' test.xml 

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

Für 'Uploads' Verwendung

zu erhalten
$ xml_grep --text_only 'Uploads' test.xml 

zu bekommen

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