Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/xml/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/shell/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何使用shell脚本从xml中的特定字段中删除CDATA_Xml_Shell - Fatal编程技术网

如何使用shell脚本从xml中的特定字段中删除CDATA

如何使用shell脚本从xml中的特定字段中删除CDATA,xml,shell,Xml,Shell,我在xml文件中有以下内容。我想使用shell脚本从特定字段“ute.sourceSystem”中删除CDATA 预期产量- <RECORD> <PROP NAME="customerType_Support"> <PVAL><![CDATA[regular]]></PVAL> </PROP> <PROP NAME="ute.sourceSystem">

我在xml文件中有以下内容。我想使用shell脚本从特定字段“ute.sourceSystem”中删除CDATA


预期产量-

<RECORD>
    <PROP NAME="customerType_Support">
            <PVAL><![CDATA[regular]]></PVAL>
        </PROP>
    <PROP NAME="ute.sourceSystem">
        <PVAL>
            <cms>
        </PVAL>
    </PROP>
</RECORD>

XML中的CDATA部分只是一个语法特性。从语义上讲,XML相当于

<RECORD>
    <PROP NAME="customerType_Support">
            <PVAL>regular</PVAL>
        </PROP>
    <PROP NAME="ute.sourceSystem">
        <PVAL>
            cms
        </PVAL>
    </PROP>
</RECORD>

请注意,它插入的是
,而不是
,因为它会创建格式错误的XML。

您知道输出不是有效的XML吗?谢谢!。我们可以使用sed或awk命令执行同样的操作吗?因为我需要安装上面的插件来实现这一点。
sed
awk
不支持XML,所以它们可以轻松地破坏数据。
<RECORD>
    <PROP NAME="customerType_Support">
            <PVAL>regular</PVAL>
        </PROP>
    <PROP NAME="ute.sourceSystem">
        <PVAL>
            cms
        </PVAL>
    </PROP>
</RECORD>
open file.xml ;
insert element normalize-space(/RECORD/PROP[@NAME="ute.sourceSystem"]/PVAL)
    into /RECORD/PROP[@NAME="ute.sourceSystem"]/PVAL ;
delete /RECORD/PROP[@NAME="ute.sourceSystem"]/PVAL/text() ;
save :b ;