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

Re: xml file reading and displaying

by Jenda (Abbot)
on Mar 31, 2007 at 22:24 UTC ( [id://607648]=note: print w/replies, xml ) Need Help??


in reply to xml file reading and displaying

Yet another solution:

use XML::Rules; my $parser = XML::Rules->new( rules => [ item => sub { '<li>' . $_[1]->{_content} . '</li>'}, list => sub { for ($_[1]->{_content}) { s/^\s+//; s/\s+$//; s{</li>\s+<li>}{</li><li>}g; } "\nTX <ol>" . $_[1]->{_content} . "</ol>\n" }, para => sub { 'TX ' . $_[1]->{_content}}, head => sub { 'TX <h3>' . $_[1]->{_content} . "</h3>"}, 'doc.body' => 'content', ] ); use Data::Dumper; my $result = $parser->parse($XML)->{'doc.body'}; for ($result) { s/^\s+//; s/\s+$//; } print $result; __END__ C:\temp>c:\temp\reformatXML.pl TX <h3>Introduction</h3> TX para 1 TX para 2 TX <h3>Individual</h3> TX para 1 TX para 2: TX <ol><li>item 1</li><li>2</li></ol>

Getting rid of the excess whitespace complicates the code somewhat.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others having an uproarious good time at the Monastery: (6)
As of 2024-04-23 12:16 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found