Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number

Re: XML Transaction - random access.

by andreychek (Parson)
on Jun 29, 2001 at 22:41 UTC ( #92756=note: print w/ replies, xml ) Need Help??

in reply to XML Transaction - random access.

If thats as big as it's going to get, you could always consider using XML::Simple to transform the XML data into a hash. The biggest problem with that would be in a case where your XML grew to be large -- you'd end up using a lot of RAM.

To use XML::Simple, you can just use code like this:

use XML::Simple; # Gets XML data from a file $hashref = XMLin('/path/to/somefile.xml'); or even: # Assumes you already have the XML data within a string $hashref = XMLin($XMLinaString);
And that would provide you with a nested hash containing all your data, properly structured (as opposed to flattened). From that point it wouldn't be too difficult to write code to randomly access the keys/data within.

And by all means, no one could ever go wrong using XML::Twig for the task if you were concerned about the size of you XML document :-)

Update: Added code example.

Comment on Re: XML Transaction - random access.
Download Code
Replies are listed 'Best First'.
Re: Re: XML Transaction - random access.
by epoptai (Curate) on Jun 30, 2001 at 00:28 UTC
    Two notes on the use of XML::Simple:

    1. Since malformed XML is fatal to the parser you may want to wrap its evocation in an eval block.
    2. Use forcearray to avoid problems with references when the returned structure has empty elements.

    $hashref = eval{ XMLin($XMLinaString, forcearray => 1) }; xml_parse_failure($@) if $@; # an error trapping sub

    Check out my Perlmonks Related Scripts like framechat, reputer, and xNN.

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others wandering the Monastery: (5)
As of 2015-11-29 12:28 GMT
Find Nodes?
    Voting Booth?

    What would be the most significant thing to happen if a rope (or wire) tied the Earth and the Moon together?

    Results (750 votes), past polls