Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

Re^2: XML parsing with XML::Rules

by mcoblentz (Scribe)
on Jun 18, 2013 at 00:02 UTC ( #1039492=note: print w/replies, xml ) Need Help??


in reply to Re: XML parsing with XML::Rules
in thread XML parsing with XML::Rules

Hi,

I tried originally with 'parse' and several other XML methods. Because I had already read in the XML document and extracted the CDATA material, the "chunk" becomes an incorrectly formed XML document (it does not have a single root element wrapping all the other elements. The CDATA content starts with a paragraph tag, which stops in the middle, then picks up with some table elements). That's where the 'junk' error comes from - Perl is complaining about a poorly formed XML document.

I was a little embarrassed that I thought "read_in_some_data" was a real method - but the conversation has been really helpful - I honestly thought the whole documentation was trying to trick me and just couldn't figure out where my error was (silly me). Jenda had alluded to just picking up the CDATA fragments and re-parsing, which led me down a whole weird dead end. He has the right approach, I just interpreted his comments incorrectly.

This XML stuff is "fussy". I'm hoping to wrap my head around all of this because having scripts like this will make the code overall much easier to maintain. Just find the feed, parse, and go.

I'm just having trouble with the recursive bits of the overall process. The data changes and thus the details have to change.

Thanks to all for pitching in. This has been a useful discussion about feeds, XML, etc.

Matt

Replies are listed 'Best First'.
Re^3: XML parsing with XML::Rules
by jakeease (Friar) on Jun 18, 2013 at 07:17 UTC

    It had slipped my mind that the summary was CDATA as I didn't look back at the previous post. And you're right, it's the explanation for the junk message. If Perl is complaining about a poorly formed XML document, it's because we are trying to convince it that $summary is XML.

    It isn't, of course, it's HTML. And that's what Jenda meant when he said

    If you want to split that into pieces you have to pass that string to another HTML or XML parser.

    I was about to suggest parsing $summary with LWP or HTML::Parser when I read poj's post. I like how he has simplified it and shown HTML::TreeBuilder handling $summary.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others pondering the Monastery: (1)
As of 2021-02-27 08:04 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?