我想获得一个特定的字符串,例如< received> 123< / received>中的123.从
一些将从URL检索的 XML.
一些将从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