Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery

Re: XML Cleanup

by mirod (Canon)
on May 23, 2008 at 10:08 UTC ( #688120=note: print w/replies, xml ) Need Help??

in reply to XML Cleanup

There are many ways to do this, but the one I usually prefer is to take advantage of XML entities: what I parse is <!DOCTYPE doc [<!ENTITY real_doc SYSTEM "$doc_file">]><doc>&real_doc;</doc>. The XML string references the real file through the entity.

This way you don't need a temporary file, and you don't touch your original data. Plus you get XML cred, amaze your friends, impress your boss... why would you do it any other way?

You can even check that it works by running this code, that tests it both with XML::Parser and with XML::LibXML:

#!/usr/bin/perl use strict; use warnings; use XML::Parser; use XML::LibXML; my $doc_file= shift @ARGV; my $xml=qq{<!DOCTYPE doc [<!ENTITY real_doc SYSTEM "$doc_file">]><doc> +&real_doc;</doc>}; { print "XML::Parser:\n"; my $t= XML::Parser->new( Style => 'Stream')->parse( $xml); } { print "XML::LibXML:\n"; my $parser = XML::LibXML->new(); my $doc = $parser->parse_string($xml); print $doc->toString; }

Replies are listed 'Best First'.
Re^2: XML Cleanup
by Your Mother (Archbishop) on May 23, 2008 at 19:55 UTC

    Neat trick!

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others lurking in the Monastery: (2)
As of 2022-01-17 00:30 GMT
Find Nodes?
    Voting Booth?
    In 2022, my preferred method to securely store passwords is:

    Results (50 votes). Check out past polls.