Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

XML Parser question

by idcrisis (Initiate)
on Sep 20, 2012 at 08:57 UTC ( #994612=perlquestion: print w/ replies, xml ) Need Help??
idcrisis has asked for the wisdom of the Perl Monks concerning the following question:

Hello ,

I am trying to parse a valid xml document using XML::RAI and see that it can identify limited number of fields that i can retrieve. How can i retrieve author or description or replycount fields from the XML document given below.

#!/usr/bin/perl use XML::RAI; my $xml=`curl -ksS "https://forums.com/rss.php?forumID=143"`; $xml =~ s/\15//g; my $feed = XML::RAI->parse($xml); for ( reverse (@{$feed->items}) ){ my $title=$_->title; my $date =$_->created ; my $date_modified; my $url =$_->link ; }

XML Format:

<?xml version="1.0" encoding="UTF-8"?> <rss version="2.0" xmlns:jf="http://forums.com/rss"> <channel> <item> <title>xxxxxxxxxxxxxxxxx</title> <link>https://forums.com/thread.php</link> <description>yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy</description> <pubDate>Wed, 19 Sep 2012 20:57:16</pubDate> <jf:creationDate>Wed, 19 Sep 2012 20:57:16 </jf:creationDate> <jf:modificationDate>Wed, 19Sep2012 20:57:16 </jf:modification +Date> <jf:date>Sep 19, 2012</jf:date> <jf:author>author1</jf:author> <jf:replyCount>3</jf:replyCount> </item> </channel> </rss>

Comment on XML Parser question
Select or Download Code
Re: XML Parser question
by tobyink (Abbot) on Sep 20, 2012 at 11:22 UTC

    It's a hack, but it looks like you should be able to "teach" XML::RAI::Item about new fields like this:

    $XML::RAI::Item::XMap->{my_author} = [qw( jf:author )];

    ... and then just use $_->my_author.

    perl -E'sub Monkey::do{say$_,for@_,do{($monkey=[caller(0)]->[3])=~s{::}{ }and$monkey}}"Monkey say"->Monkey::do'
Re: XML Parser question
by shmem (Canon) on Sep 20, 2012 at 15:17 UTC
    How can i retrieve author or description or replycount fields from the XML document given below.

    Strip the bogus namepsace identifier jf. Where did you get that from? certainly not from forums.com.

    $xml =~ s/jf://g;

    Add the attributes you want according to the docs:

    XML::RAI::Item->add_mapping($_,$_) for qw(modificationDate author replyCount);

    There might be a way to register xmlns:jf within the XML modules suite you are using. Reading the docs might help...

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://994612]
Approved by marto
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (8)
As of 2014-07-31 21:21 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite superfluous repetitious redundant duplicative phrase is:









    Results (253 votes), past polls