Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

Re^3: read a file and insert closing tags if not present

by GrandFather (Saint)
on Mar 29, 2007 at 08:00 UTC ( [id://607180]=note: print w/replies, xml ) Need Help??


in reply to Re^2: read a file and insert closing tags if not present
in thread read a file and insert closing tags if not present

HTML::TreeBuilder handles that simple case:

use strict; use warnings; use HTML::TreeBuilder; my $sgml = <<SGML; <greeting class="simple">Hello, world! SGML my $root = HTML::TreeBuilder->new (); $root->ignore_unknown (0); $root->parse ($sgml); print $root->guts (0)->as_XML ();

Prints:

<greeting class="simple">Hello, world!</greeting>

although I'd not guarantee it will accept everything a real SGML document may contain.


DWIM is Perl's answer to Gödel

Replies are listed 'Best First'.
Re^4: read a file and insert closing tags if not present
by valavanp (Curate) on Mar 29, 2007 at 09:45 UTC
    Hi grandfather, Your solution is fine. But when i give like this extra tags have been inserted. how can i avoid this.
    use strict; use warnings; use HTML::TreeBuilder; my $sgml = <<SGML; <html> <greeting class="simple">Hello, world!<head>heading</head> </html> SGML my $root = HTML::TreeBuilder->new (); $root->ignore_unknown (0); $root->parse ($sgml); print $root->guts (0)->as_XML ();
    Thanks for your suggestion

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others wandering the Monastery: (5)
As of 2024-04-25 14:36 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found