ASPN ActiveState Programmer Network
ActiveState
/ Home / Perl / PHP / Python / Tcl / XSLT /
/ Safari / My ASPN /
Cookbooks | Documentation | Mailing Lists | Modules | News Feeds | Products | User Groups


Recent Messages
List Archives
About the List
List Leaders
Subscription Options

View Subscriptions
Help

View by Topic
ActiveState
.NET Framework
Open Source
Perl
PHP
Python
Tcl
Web Services
XML & XSLT

View by Category
Database
General
SOAP
System Administration
Tools
User Interfaces
Web Programming
XML Programming


MyASPN >> Mail Archive >> perl-xml
perl-xml
xpath problem with XML::XPath and LibXML
by redicaps other posts by this author
Jun 21 2009 3:47AM messages near this date
view in the new Beta List Site
Re: Handling ? (pound sterling) symbols in content | Re: xpath problem with XML::XPath and LibXML
& XSLT hi all,
Below is the xml I want to parse with XPath, however, I met some problems  
with both XML::XPath and XML::LibXML;

<?xml version="1.0" encoding="UTF-8"?> 
<feed xmlns="http://www.w3.org/2005/Atom"  
xmlns:db="http://www.douban.com/xmlns/"  
xmlns:gd="http://schemas.google.com/g/2005"
xmlns:opensearch="http://a9.com/-/spec/opensearchrss/1.0/"> 
<title> friends</title>
<author> 
<link href="http://api.douban.com/people/ahbei" rel="self"/> 
<link href="http://www.douban.com/people/ahbei/" rel="alternate"/> 
<link href="http://t.douban.com/icon/u1000001-14.jpg" rel="icon"/> 
<name> ahbei</name>
<uri> http://api.douban.com/people/1000001</uri>
</author> 
<opensearch:startIndex> 1</opensearch:startIndex>
<opensearch:itemsPerPage> 2</opensearch:itemsPerPage>
<opensearch:totalResults> 114</opensearch:totalResults>
<entry> 
<id> http://api.douban.com/people/1010394</id>
<title> Engo</title>
<link href="http://api.douban.com/people/1010394" rel="self"/> 
<link href="http://www.douban.com/people/akin/" rel="alternate"/> 
<link href="http://t.douban.com/icon/u1010394-10.jpg" rel="icon"/> 
<link href="http://www.halfull.cn" rel="homepage"/> 
<content> 
http://www.douban.com/group/topic/3750385/
</content> 
<db:location id="beijing"> beijing</db:location>
<db:uid> akin</db:uid>
</entry> 
<entry> 
<id> http://api.douban.com/people/1276180</id>
<title> wo</title>
<link href="http://api.douban.com/people/1276180" rel="self"/> 
<link href="http://www.douban.com/people/movie007wn/" rel="alternate"/> 
<link href="http://t.douban.com/icon/u1276180-40.jpg" rel="icon"/> 
<content> 
???????????????
</content> 
<db:location id="beijing"> beijing</db:location>
<db:uid> movie007wn</db:uid>
</entry> 
</feed> 

Here is the XML::XPath code:

my $xml = XML::XPath-> new( xml => $string);
my $nodeset = $xml-> findnodes('//entry');
foreach my $node ( $nodeset-> get_nodelist){
print $node-> findvalue('//title'),"\n";
}

I got
friendsEngowo
friendsEngowo
which are all the title nodes of this xml, it seems like each $node has all  
the information of this XML. Dose any one knows what the problem
is?


Then I try to use XML::LibXML instead, here is the code

my $xml = XML::LibXML-> new->parse_string( $string);
my @nodeset = $xml-> find('//entry');
print Dumper @nodeset;

I got
$VAR1 = bless( [], 'XML::LibXML::NodeList' );

which means I got nothing, entry nodes for this xml are not found, so can  
anybody help me?
Thread:
redicaps
Aristotle Pagaltzis
redicaps
Shlomi Fish
Michael Ludwig
redicaps
Grant McLean
Bjoern Hoehrmann

Privacy Policy | Email Opt-out | Feedback | Syndication
© ActiveState Software Inc. All rights reserved