如何使用Twig模块从XML中删除注释
发布时间:2020-12-16 22:55:10 所属栏目:百科 来源:网络整理
导读:我正在使用 XML :: Twig模块从 XML文件中删除所有注释.示例文件可以是 – ?xml version="1.0" encoding="UTF-8"?Node_Anode A content 1!-- One Line Comment A1--![CDATA[this portion within the two comments is beingREMOVED which is not the intention
我正在使用
XML :: Twig模块从
XML文件中删除所有注释.示例文件可以是 –
<?xml version="1.0" encoding="UTF-8"?> <Node_A> node A content 1 <!-- One Line Comment A1--> <![CDATA[this portion within the two comments is being REMOVED which is not the intention]]> <!-- Two Line Comment Two Line Comment--> node A content 3 <!-- Two Line Comment Two Line Comment--> <![CDATA[this portion within the two comments is being REMOVED which is not the intention]]> <!-- Two Line Comment Two Line Comment--> <![CDATA[ this portion is fine]]> <Node_B> node B content <Node_C> node c content </Node_C> <!-- One Line Comment --> some data one <!-- Multi Line Comment Line 3Comment 1Line Comment 2Line Comment Line 5Comment Line Comment--> some data again two <!-- Multi Line Comment Line 3Comment Line 5Comment Line Comment--> few more </Node_B> </Node_A> 我用过的脚本像 – #!/usr/bin/perl use strict; use warnings; use XML::Twig; my $infile = 'demo.xml'; my $twig = XML::Twig->new (comments => 'drop',pretty_print => 'indented')->parsefile($infile); $twig->print (); 此脚本正在删除两条注释中的“CDATA”部分 <?xml version="1.0" encoding="UTF-8"?> <Node_A> node A content 1 <![CDATA[ this portion is fine]]><Node_B> node B content <Node_C> node c content </Node_C> some data one some data again two few more </Node_B></Node_A> 我必须添加以保留所有CDATA部分和其他内容,只是为了 提前致谢. 解决方法
当我使用您发布的demo.xml文件运行脚本时,我得到输出:
<?xml version="1.0" encoding="UTF-8"?> <Node_A> node A content 1 <![CDATA[this portion within the two comments is being REMOVED which is not the intention]]> node A content 3 <![CDATA[this portion within the two comments is being REMOVED which is not the intention]]><![CDATA[ this portion is fine]]><Node_B> node B content <Node_C> node c content </Node_C> some data one some data again two few more </Node_B></Node_A> 哪个看起来对我好.我怀疑你有一个XML::Twig的错误版本(或XML::Parser,它取决于).我使用的是Perl 5.14.2,XML :: Twig 3.35和XML :: Parser 2.41. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
相关内容
- ios – UIWebview didReceiveAuthenticationChallenge
- c – 并行任务通过boost :: thread获得比ppl或OpenMP更好的
- 如何在C#(windows app)中将文件从本地系统复制到其他系统?
- ajax跨域请求Access-Control-Allow-Origin
- Geodatabase Toolset (GDBT)介绍
- SQLite数据库与Contentprovider(2)
- c# – ViewModel中计时器的更好解决方案?
- pureMVC + BlazeDS 3.3 + Spring2.5.6 + iBAITS 2.3.4 +mys
- jsoncpp解析 json对象
- 狗屎一样的React(第八节,React-router 4.0的使用姿势)