Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

Re: XML::LibXML getElementsById problem

by santonegro (Scribe)
on Dec 15, 2005 at 17:42 UTC ( #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? | Other CB clients
Other Users?
Others pondering the Monastery: (2)
As of 2021-12-07 03:46 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    R or B?



    Results (33 votes). Check out past polls.

    Notices?