Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
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"; } }

In reply to Re^2: XML::Simple "transforming data" by Grundle
in thread XML::Simple "transforming data" by Grundle

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others sharing their wisdom with the Monastery: (4)
As of 2024-04-19 13:29 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found