xml - 如何在perl中获取xml元素的第一个和最后一个子元素

标签 xml perl

<note>
    <to>Tove</to>
    <from>Jani</from>
    <heading>Reminder</heading>
    <body>Don't forget me this weekend!</body>
</note>

当元素名称作为节点给出时,答案应该是 to 和 body

最佳答案

使用xshXML::LibXML 的包装器:

open data.xml ;
ls (/note/*[1] | /note/*[last()]) ;

关于xml - 如何在perl中获取xml元素的第一个和最后一个子元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18982995/

相关文章:

Android 开关小部件 : Setting android:track causes thumb and track to not show up

xml - 必须将所有 AS400 DB2 字段名称放到一个表中

xml - Groovy 用 xpath 替换 xml 中的节点值

regex - Perl 正则表达式 |如何从文件中排除单词

java - 分发 XML 文件

c# - "Could not find schema information for the element"- 但我的架构文件确实包含该元素的信息

perl - 在 Perl 中,如何禁用在所需脚本中加载的 CGI::Carp?

linux - Perl脚本Cron/环境问题

regex - 无法使用 perl 和正则表达式将模式匹配保存在数组中

linux - Perl 编译错误 - make : [pod/perltoc. pod] 段错误