XML标记最后关闭 [英] XML tag closing at the end

查看:340
本文介绍了XML标记最后关闭的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


我是Perl的新手,我想在每章结尾处关闭book-part标签,并且我有n个章节,例如,book-part应该在下一章开始之前关闭,
我尝试了以下代码,但无法显示任何更改

Hi,
I''m newbie to Perl,i want to close the book-part tag at the end of each chapter and i have n chapters,i.e)book-part should be close before the next chapter begin,
i tried the below code but it couldn''t show any changes

if($str =~ /<book-part book-part-type="chapter" id="chapter\d+">((?:(?!<\/?book-part book-part-type="chapter" id="chapter\d+">).)*)(?=<book-part book-part-type="chapter" id="chapter\d+">)/sgi)
    {
    $str .="<book-part>";
    }


每章都以下面的标签开头


each chapter begin with this below tag

<book-part book-part-type="chapter" book-part-number="\d+" id="chapter\d+">


我想生成这样的输出


and i want to generate a output like this

</book-part>
<book-part book-part-type="chapter" book-part-number="2" id="chapter2"


</book-part>

是第一章的结束标记,

<book-part book-part-type>

是第二章的开始标记.
请任何人帮助我解决我的问题.......

is a second chapter''s opening.
plz any one help me to solve my problem.......

推荐答案

str =〜/< book-part book-part-type = " id = " 章节\ d +">((?:(?!< \/?book-part book-part-type = 章" id = 章\ d +">).)*)(?=<book-partbook-part-type = " id = 章\ d +">)/sgi) {
str =~ /<book-part book-part-type="chapter" id="chapter\d+">((?:(?!<\/?book-part book-part-type="chapter" id="chapter\d+">).)*)(?=<book-part book-part-type="chapter" id="chapter\d+">)/sgi) {


str .= " ; }
str .="<book-part>"; }


每章都以下面的标签开头


each chapter begin with this below tag

<book-part book-part-type="chapter" book-part-number="\d+" id="chapter\d+">


我想生成这样的输出


and i want to generate a output like this

</book-part>
<book-part book-part-type="chapter" book-part-number="2" id="chapter2"


</book-part>

是第一章的结束标记,

<book-part book-part-type>

是第二章的开始标记.
请任何人帮助我解决我的问题.......

is a second chapter''s opening.
plz any one help me to solve my problem.......


问题似乎是,您的如果"条件将永远不会得到满足(错误的假设和/或也是如此)复杂吗?).

注意:XML是一种免费格式,即内容可以分布在多行中.

如果您需要修改整个XML文件,那么最好将整个文件插入一个字符串并立即处理该数据.

来自STDIN的内容:
The issue seems to be, that your "if" condition will never be met (wrong assumptions and/or too complicated?).

Note: XML is a free format, i.e. the content may be spread over multiple lines.

If you need to modify the whole XML file, then it''s best to slurp in the whole file into one string and process that data at once.

Slurp from STDIN:
my


这篇关于XML标记最后关闭的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆