如何使用XML :: Twig从URL中提取一些XML数据?
发布时间:2020-12-16 23:01:56 所属栏目:百科 来源:网络整理
导读:我想获得一个特定的字符串,例如 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
我想获得一个特定的字符串,例如< received> 123< / received>中的123.从
一些将从URL检索的 XML. 我写了一段代码,但仍然遇到错误信息:
我该如何解决? 代码: 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 (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |