Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??

This by no way the finish product but it may help you get started.

#!/usr/bin/perl -w # use strict; my ($xmlvar,$i,$k,$v); my %hash = (); while (<DATA>) { print; chomp($_); $i = 0; while ($i++ < length($_)) { print "1: '"; print $1 if /(<)/gc; print "', pos=", pos, "\n"; $k = ''; print "2: '"; $k = $1 if /\G([A-Za-z0-9]+)/gc; print "$k', pos=", pos, "\n" +; my $f = '</'.$k.'>' if defined $k; print "3: '"; print $1 if /(>)/gc; print "', pos=", pos, "\n"; $v = ''; print "4: '"; $v = $1 if /\G(.*)$f/gc; print "$v', pos=", pos, "\n"; $i = pos; print $k,' << ',$v,"\n"; $hash{$k} .= $v.','if defined $k; } print "Final: '$1', pos=",pos,"\n" if /\G(.)/; } s/,\z// for values %hash; while ( my ($key, $value) = each(%hash) ) { print "$key => $value\n"; } __DATA__ <dataset> <row> <name>dog</name> <category>home pet</category> </row> <row> <name>cat</name><category>home pet</category> </row> <row> <name>penguin</name> <category>fish</category> </row> <row> <name>lax</name> <category>wile</category> </row> <row> <name>whale</name> <category>fish</category> </row> <row> <name>ostrich</name> <category>bird</category> </row> <row> <name>catfish</name> <category>fish</category> </row> </dataset>

In reply to Re: Parsing XML...by hand (ugh) by Generoso
in thread Parsing XML...by hand (ugh) by raindog308

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 contemplating the Monastery: (5)
As of 2024-04-25 18:46 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found