<note>
<to>Tove</to>
<from>Jani</from>
<heading>Reminder</heading>
<body>Don't forget me this weekend!</body>
</note>
当元素名称作为节点给出时,答案应该是 to 和 body
最佳答案
使用xsh , XML::LibXML 的包装器:
open data.xml ;
ls (/note/*[1] | /note/*[last()]) ;
关于xml - 如何在perl中获取xml元素的第一个和最后一个子元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18982995/