Re: [nokogiri-talk] Nokogiri lose my attribute's value named 'multiple'

29 views
Skip to first unread message

Walter Lee Davis

unread,
May 13, 2013, 8:55:07 AM5/13/13
to nokogi...@googlegroups.com
First, I don't believe that an input can have a multiple attribute. A select can. And the inverse of multiple="multiple" is not multiple="false", it's simply the absence of the multiple attribute altogether. Any string at all in the value portion of the multiple attribute will signal that the attribute is true. And in HTML5, just having it there at all will have it work. These are all functionally identical:

<select name="foo" multiple="bar">...</select>
<select name="foo" multiple="true">...</select>
<select name="foo" multiple>...</select>
<select name="foo" multiple="multiple">...</select>

The last two are considered the normal form. To make a single-value select, you would use this instead:

<select name="foo">...</select>

Walter

On May 13, 2013, at 8:20 AM, Tassadar Liu wrote:

> Here's the code:
>
> require 'nokogiri'
>
>
> doc
> = Nokogiri::HTML("<!DOCTYPE html><html><input multiple='false' id='test' some='2'/><div multiple='true'></div></html>")
>
>
> puts doc
> .
> errors
>
> doc
> .css("input").each do |el|
>
> puts el
> .attributes['multiple']
> end
>
>
> puts doc
> .to_html
>
> And here's the output:
>
> false
> <!DOCTYPE html>
> <html><body>
> <input multiple id="test" some="2"><div multiple></div>
> </body></html>
> [Finished in 2.0s]
>
> Where are the two 'false's??
>
>
>
>
> --
> You received this message because you are subscribed to the Google Groups "nokogiri-talk" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to nokogiri-tal...@googlegroups.com.
> To post to this group, send email to nokogi...@googlegroups.com.
> Visit this group at http://groups.google.com/group/nokogiri-talk?hl=en.
> For more options, visit https://groups.google.com/groups/opt_out.
>
>

Mike Dalessio

unread,
May 13, 2013, 9:51:05 AM5/13/13
to nokogiri-talk
Agree. libxml2 here is simply obeying the boolean convention around the "multiple" attribute, regardless of the tag.

Tassadar Liu

unread,
May 13, 2013, 11:54:51 PM5/13/13
to nokogi...@googlegroups.com
But some jquery plugins require this multiple='true' indeed, can i turn off the correction??

在 2013年5月13日星期一UTC+8下午8时55分07秒,Walter Lee Davis写道:

Walter Lee Davis

unread,
May 14, 2013, 9:25:58 AM5/14/13
to nokogi...@googlegroups.com
See if you can use valid HTML code: either multiple="multiple" (or just multiple all by itself) if you're allowed to choose multiple values, and leave it off entirely if you aren't. And please confirm -- you are using this attribute on a <select> not an <input>, right?

If you are using jQuery, it should absolutely require you to start with valid HTML or XHTML. Browsers are endlessly forgiving of "tag soup" -- JavaScript catches cold and dies at the slightest sniffle of invalid HTML.

Finally, Nokogiri should not be doing anything to your <script> tag contents beyond a little whitespace cleanup from the prettifier. If this construction is inside a script block, it shouldn't be touched there at all, methinks.

Walter

rhapsodyn

unread,
May 14, 2013, 9:59:11 PM5/14/13
to nokogi...@googlegroups.com
Thank you Walter, i know THE jquery-plugin is the one to blame.
I temporarily replace the 'multiple' with some other 'blahblahattributename' and put it back later as a workaround


2013/5/14 Walter Lee Davis <wa...@wdstudio.com>
You received this message because you are subscribed to a topic in the Google Groups "nokogiri-talk" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/nokogiri-talk/6EIRjcVR1v8/unsubscribe?hl=en.
To unsubscribe from this group and all its topics, send an email to nokogiri-tal...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages