XmlStarlet可以在复制期间保留CDATA吗? [英] Can XmlStarlet preserve CDATA during copy?
本文介绍了XmlStarlet可以在复制期间保留CDATA吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
使用复制时,如何使XmlStarlet保留CDATA?必须维护<![CDATA []]>
,因为生成(和使用)数据的应用程序坚持对某些数据使用CDATA指令。
How can I make XmlStarlet preserve CDATA when using copy? The <![CDATA[ ]]>
must be maintained because the application that generated (and uses) the data insists on having the CDATA directive around certain data.
Example.xml
Example.xml
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<RSLogix5000Content SchemaRevision="1.0" SoftwareRevision="20.01" >
<Controller Use="Target" Name="SOME_TARGET_NAME" ProcessorType="1789-L60">
<Tags>
<Tag Name="gstrScrap" TagType="Base" DataType="STRING" Constant="false" ExternalAccess="Read/Write">
<Data>05 00 00 00 53 43 52 41 50 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00</Data>
<Data Format="String" Length="5">
<![CDATA['SCRAP']]>
</Data>
</Tag>
</Tags>
</Controller>
</RSLogix5000Content>
使用命令;
xml sel -t -c "RSLogix5000Content/Controller/Tags/Tag" Example.xml
生成应用程序无法处理的数据,因为'SCRAP'附近的<![CDATA []]>
已删除;
Generates data that the application cannot handle because <![CDATA[ ]]>
was removed from around 'SCRAP';
<Tag Name="gstrScrap" TagType="Base" DataType="STRING" Constant="false" ExternalAccess="Read/Write">
<Data>05 00 00 00 53 43 52 41 50 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00</Data>
<Data Format="String" Length="5">
'SCRAP'
</Data>
</Tag>
推荐答案
您要去的地方:
xml sel -t -c "RSLogix5000Content/Controller/Tags/Tag" Example.xml >t1.xml
xml ed -i "/Tag/Data/text()" -t text -n "" -v "<![CDATA[" t1.xml >t2.xml
xml ed -a "/Tag/Data/text()" -t text -n "" -v "]]>" t2.xml >t3.xml
sed -r "s/<!\[CDATA\[/<![CDATA[/g; s/\]\]>/]]>/g" t3.xml >t4.xml
需要 sed ,除非您在xml中转义了字符:
you do not need sed unless you have escaped characters in your xml:
xml sel -t -c "RSLogix5000Content/Controller/Tags/Tag" Example.xml >t1.xml
xml ed -i "/Tag/Data/text()" -t text -n "" -v "<![CDATA[" t1.xml >t2.xml
xml ed -a "/Tag/Data/text()" -t text -n "" -v "]]>" t2.xml >t3.xml
xml unesc <t3.xml >t4.xml
这篇关于XmlStarlet可以在复制期间保留CDATA吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文