laziness, impatience, and hubris | |
PerlMonks |
Re: Using HTML::TreeBuilder to change the DOCTYPE declarationby ikegami (Patriarch) |
on Nov 04, 2008 at 11:20 UTC ( [id://721351]=note: print w/replies, xml ) | Need Help?? |
The doctype is stored as an attribute of the root element where the attribute name is "_decl" and the value is an HTML::Element object, so basically, you want
Since look_down doesn't allow us to check if an attribute was specified we'll have to provide our own handler.
But why use look_down at all? The only possible node it could return is the root node. The above code boils down to
Now that we have the declaration, let's move on to changing it. It makes no sense to use splice_content to modify attributes. attr is the proper method.
Since the entire purpose is to replace the declaration, let's create a new declaration rather than dying if it's absent.
All together:
In Section
Seekers of Perl Wisdom
|
|