Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

Re^2: nested loops and escaping in XML::Generator

by geektron (Curate)
on Jul 12, 2006 at 21:17 UTC ( [id://560823]=note: print w/replies, xml ) Need Help??


in reply to Re: nested loops and escaping in XML::Generator
in thread nested loops and escaping in XML::Generator

I'm confused about why you want to avoid XML::Generator's auto-escaping of data. Because when you use an XML parser, the data should be auto-unescaped.

Because I'm trying (for lack of a better way of doing it) to insert pre-rolled XML into a larger XML document. Without disabling escaping, I get:

<imageinfo> &lt;imageurl1 /&gt;&lt;imagecaption1 /&gt;&lt;imageurl2 /&gt;&lt;image +caption2 /&gt;&lt;imageurl3 /&gt;&lt;imagecaption3 /&gt;&lt;imageurl4 + /&gt;&lt;imagecaption4 /&gt; </imageinfo>
From:
$generator->imageinfo( $imageSection ),
(remember that $imageSection was generated within a loop). Not a pretty sight, not valid XML ...

I'm also confused about your data format. So am I. It's the requirement from a third party, and cannot be changed. Essentially, I'm trying to work *around* someone else's bizarro-world XML format.

Replies are listed 'Best First'.
Re^3: nested loops and escaping in XML::Generator
by Tanktalus (Canon) on Jul 12, 2006 at 21:48 UTC

    Ok, that's extremely helpful information. The data format is a "I wanna slap the guy who forced this on the world" answer. I can accept that. There are many people I know who deserve slapping. Of course, I say this with a severe Captain-Jack-Sparrow accent ;-)

    The first part of your node, however, is really helpful. I didn't understand the problem at first. Now, however, it looks like you want to do this (based only on the docs, not on trying it myself):

    use XML::Generator escape => 1; $generator->imageinfo( \$imageSection );
    To me, this seems like a reasonable tradeoff. You're saying, "Trust me, this is valid XML here." And you're right - it is. Other than abandoning XML::Generator, this seems like your best option. You get escaping most of the time (which is what you should want), and can override it in the rare circumstance where you really want to.

    Personally, I wouldn't have used XML::Generator, but XML::Twig, based on my XML decision tree. But the wonderful thing about Perl is that there's so many ways to do things - do it the way that makes the most sense to you ;-)

      Passing \$imageSection isn't something I'd thought of. I'll give it a shot.

      XML::Twig *looked* a little less straightforward and whatnot to me ... I just want to spit the XML out, not parse it. That's someone else's job (this annoying 3rd party), and as long as I can spit out something in his (company's) format, I'm safe.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others romping around the Monastery: (3)
As of 2024-04-20 02:54 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found