Beefy Boxes and Bandwidth Generously Provided by pair Networks
Come for the quick hacks, stay for the epiphanies.
 
PerlMonks  

Re: XML::LibXML getElementsById problem

by santonegro (Scribe)
on Dec 15, 2005 at 17:42 UTC ( [id://517041]=note: print w/replies, xml ) Need Help??


in reply to XML::LibXML getElementsById problem

Wow, thank god for XML::TreeBuilder
my $tree = XML::TreeBuilder->new_from_content(<<EOF); ?xml version="1.0"?> <root> <aaa id='test'> <bbb/> </aaa> </root> EOF my $elem = $tree->look_down(id => 'text'); $elem->this; $elem->that;

Replies are listed 'Best First'.
Re^2: XML::LibXML getElementsById problem
by mirod (Canon) on Dec 15, 2005 at 19:19 UTC

    Oh, if we are pimping alternate modules, then of course id IS magical in XML::Twig:

    #!/usr/bin/perl -w use strict; use XML::Twig; my $xml_string = <<EOF; <?xml version="1.0"?> <root> <aaa id='test'> <bbb/> </aaa> </root> EOF my $t= XML::Twig->nparse( $xml_string); my $elem= $t->getElementById( 'test'); $elem->print;

    And of course you can use it to process HTML too (it sub-contracts the HTML to XHTML conversion to HTML::TreeBuilder):

    #!/usr/bin/perl -w use strict; use XML::Twig; my $html_string = <<EOF; <html> <head><title>Just a quick example</title></head> <body><h1>Example</h1> an example<p> <div id="test">gotcha!</div> <hr> </html> EOF my $t= XML::Twig->new->parse_html( $html_string); my $elem= $t->getElementById( 'test'); $elem->print;

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others about the Monastery: (7)
As of 2024-04-23 12:34 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found