Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

Hello, seekers of Perl Wisdom,

I have been using the excellent HTML-Tree distribution by Sean M. Burke for a few days now. Today I ran into problems when trying to create an element with an attribute without a value assigned to it, such as:

<img src="blah.png" ismap>

There seems to be no way to create such a node with new_from_lol(), because

['img', {'ismap' => undef}, ]

deletes the attribute and

['img', {'ismap' => ""}, ]

creates a node such as <img ismap="">.

I then created a file containing <img ismap> and created a tree from the file with HTML::TreeBuilder. It turns out that as_HTML() dumps the node as <img ismap>, but
$node->attr('ismap')
returns "ismap"! Does anyone know if this is intentional? I.e., is one to check these attributes against values consisting of their own name to look up such HTML elements in a parse tree?

Now comes the weird part: I created a file with the element <img IsMap> (notice the capitalization). as_HTML() dumps that one as <img ismap="IsMap">. That can't be right! Looks like a bug, unless I'm really doing something wrong.

I've already contacted the author, but I figured someone here might know something ...?


Any ideas?
Thanks,
John

Replies are listed 'Best First'.
Re: using HTML::Element with an attribute name without value
by Joost (Canon) on Apr 09, 2005 at 16:01 UTC
    According to the HTML specs, <tag att> is equivalent to <tag att="att">. Also XHTML mandates lower-case tags (which incidentally, are easier to type). I guess you should go for ['img', { ismap => 'ismap' }] just to be on the safe side.

    update: just FYI: XHTML doesn't allow attributes without values, so in XHTML you need to do att="att".

      I didn't know that <tag att> was equivalent to <tag att="att">...

      That answers my question :-)

      Thank you.
      John