Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

Re: XML Transaction - random access.

by andreychek (Parson)
on Jun 29, 2001 at 22:41 UTC ( [id://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 :-)
-Eric

Update: Added code example.

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?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others contemplating the Monastery: (1)
As of 2024-04-24 15:04 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found