Re: [xml] Saving an element into memory

On Wed, 19 Dec 2001 14:25:30 +1100
"Andrew Nesbit" <andrew nesbit csiro au> wrote:

Hi all,

I need to accomplish the following task:

1. read an XML document into memory
2. traverse to a child element of the root node
3. save that child element into a memory buffer as a standalone XML 
document, so that it can be reprocessed as an XML document at a much 
later stage.

How can I accomplish this using libxml? I think (although I'm not sure) 
that xmlElemDump() does something like this, but the problem is that it 
saves to a file, not to a memory buffer. If somebody could help me, that 
would be really cool.

Something similar was asked recently on the perl-xml list :

On Mon, 10 Dec 2001, Mark Riehl wrote:

All - Is it possible redirect the output of XML::Writer to a scalar? 

The reason I ask is that I'm using XML::Writer to generate a large XML 
document, and then using LibXSLT to apply several stylesheets to generate 
various reports.  Rather than write the file to disk and then immediately 
reread it, I'd like to be able to parse the file and apply the stylesheets 
w/o writing to disk. 

Aaron Straup Cope <asc vineyard net> replied:
use XML::Writer;
use IO::Scalar;

my $xml    = undef;
my $writer = undef;

tie(*STDOUT, 'IO::Scalar', \$xml)
$writer = new XML::Writer;

# Do stuff here...

# Make sure you reset STDOUT
# to STDOUT or things will start
# to get weird.
untie *STDOUT;

return $xml;

So I *guess* that it would be possible to tie the output of libXML to IO::Scalar as in this code. I may well 
be incorrect, and expect to be corrected...

Nationalism is an infantile sickness. It is the measles of the human race.   
 - Albert Einstein

Attachment: pgpNT4zhyUl9G.pgp
Description: PGP signature

[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]