Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic

Re^2: XML::Simple "transforming data"

by Grundle (Scribe)
on Mar 21, 2005 at 21:32 UTC ( #441319=note: print w/replies, xml ) Need Help??

in reply to Re: XML::Simple "transforming data"
in thread XML::Simple "transforming data"

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://441319]
and the web crawler heard nothing...

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

    No recent polls found