Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

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 :-)
-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
Node Status?
node history
Node Type: note [id://92756]
help
Chatterbox?
[talexb]: TStanley I'm flying to Vegas in two weeks time. After that flights leaving Vegas and Phoenix are late at night .. I've been hearing that it gets so hot that the air isn't dense enough for planes to take off. Weird. Guess you won't have that problem.
[Corion]: Yay, vacation time now - one week off work (but a Perl workshop in the middle ;)) )
[talexb]: TStanley I just realized that I was in your area for a convention back in April. We were at the high school for the weekend, the one with the long driveway. Nice spot.
[TStanley]: I am heading to Arlington, Virginia next week, then I get to spend an entire week at home. Looking forward to that as I will have spent 7 weeks on the road by the end of next week

How do I use this? | Other CB clients
Other Users?
Others avoiding work at the Monastery: (11)
As of 2017-06-23 14:16 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    How many monitors do you use while coding?















    Results (548 votes). Check out past polls.