如何使用XML :: Twig从URL中提取一些XML数据?

前端之家收集整理的这篇文章主要介绍了如何使用XML :: Twig从URL中提取一些XML数据?前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我想获得一个特定的字符串,例如< received> 123< / received>中的123.从
一些将从URL检索的 XML.

我写了一段代码,但仍然遇到错误信息:

Attempt to bless into a reference at /usr/share/perl5/XML/Twig.pm line 392.

我该如何解决

代码

use XML::Twig;
use LWP::Simple;

my $url = 'http://192.168.1.205:13000/status.xml';
my $twig = new XML::Twig(TwigRoots => {
'smsc/received' => sub {$author = $_[1]->text;  }});
$twig->nparse( $url );
$twig->print;

解决方法

nparse为你处理新的(因此’n’),在这种情况下你想要的可能是xparse,或者只是让模块弄清楚并执行此操作:

my $url= 'http://192.168.1.205:13000/status.xml';
my $twig= XML::Twig->parse( twig_roots => 
                              { 'smsc/received' => sub { $author= $_[1]->text;}},$url
                           );
$twig->print; # I am not sure why you print the twig instead of just $author

猜你在找的XML相关文章