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

Re: XML::Simple "transforming data"

by merlyn (Sage)
on Mar 21, 2005 at 20:42 UTC ( #441298=note: print w/replies, xml ) Need Help??

in reply to XML::Simple "transforming data"

The point of XML::Simple is to have a way to specify a Perl data structure with XML, and to serialize that data structure into some valid XML representation. It's not meant for very specific structure control in either direction, and if you find yourself trying to tweak things to get it to be precisely as you wish, you've probably gone beyond its abilities.

If you want to manage precise XML transformations, look in to XML::LibXML or the higher-level xsh scripting language. I did a column on that a while back.

-- Randal L. Schwartz, Perl hacker
Be sure to read my standard disclaimer if this is a reply.

Replies are listed 'Best First'.
Re^2: XML::Simple "transforming data"
by Grundle (Scribe) on Mar 21, 2005 at 21:32 UTC
    Ironically I am using XML::LibXML later on in the same program. I opted to use XML::Simple because XML::LibXML was choking on a very large file. My solution was to break it up into smaller sections so that the majority of the data could be parsed. XML::Simple has no problem reading in all the data I fed it, but the outputing structure is not what I desired.

    My ultimate conclusion was to skip a data structure altogether for breaking up the file and just do a straight regex across the whole file. This preserves my structure exactly and allows me to specify which tags to separate across. Since I am working with a set standard (docbook) there should be no surprising or malformed tags (unless I am fed a corrupted file).

    What you said about being beyond XML::Simple's capabilities, led me in this direction. Thanks for letting me know that it was time to go down another path.

    sub splitNode2{ my ($name, $root, $tag, $filename) = @_; #print "opening file [$filename]\n"; if(!open(READ, "$filename")){ die "Cannot open file [$filename] for reading\n"; } my $content = ""; while(my $line = <READ>){ $content .= $line; } #print "matching <$tag>\n"; my @matches = $content =~ /(<$tag.*?>.*?<\/$tag>)/sg; if(scalar(@matches) < 1){ writeFile($name, "", $content); #writes the string to a file return 0; } my $count = 1; foreach (@matches){ writeFile("$name"."_"."$count", "", $_); $count++; #print "match: $_\n\n\n"; } }

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others contemplating the Monastery: (5)
As of 2023-01-31 10:33 GMT
Find Nodes?
    Voting Booth?

    No recent polls found