Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

Re^2: Seemingly Valid HTML which crashes HTML::TreeBuilder::XPath

by mldvx4 (Friar)
on Nov 10, 2023 at 13:13 UTC ( [id://11155543] : note . print w/replies, xml ) Need Help??


in reply to Re: Seemingly Valid HTML which crashes HTML::TreeBuilder::XPath
in thread Seemingly Valid HTML which crashes HTML::TreeBuilder::XPath

The objectify_text call just seems to invert the problem. Though I can be rather obtuse and may not see the right way to use it.

I might be able to fit XML::LibXML into the full script and replace HTML::TreeBuilder::XPath. Here is my sketch,

#!/usr/bin/perl use XML::LibXML; use strict; use warnings; my $tree = XML::LibXML->load_xml(IO => \*DATA); my $dtd = XML::LibXML::XPathContext->new( $tree->documentElement() ); $dtd->registerNs( 'u' => 'http://www.w3.org/1999/xhtml' ); for my $body ($dtd->findnodes('//u:body')) { # print $body->toString; for my $n ($body->childNodes()) { print $n->toString; } } print "\n"; print "OK\n"; exit(0); __DATA__ <!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta name="generator" content= "HTML Tidy for HTML5 for Linux version 5.6.0" /> <title></title> </head> <body> <p>foo</p> <p>bar</p> trololo </body> </html>

Replies are listed 'Best First'.
Re^3: Seemingly Valid HTML which crashes HTML::TreeBuilder::XPath
by hippo (Bishop) on Nov 10, 2023 at 14:40 UTC

    Your code as provided runs fine for me:

    $ perl 11155543.pl <p>foo</p> <p>bar</p> trololo OK $

    If that isn't what you want/expect then you will need to show what you do expect also.


    🦛