-
-
Notifications
You must be signed in to change notification settings - Fork 905
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Detecting empty elements with XML::Reader #262
Comments
Can you please write up a (failing) unit test expressing exactly what you'd like to see? Linking to a gist from this ticket would be perfect. |
Ping: jflieber -- is this still needed? |
Yes, I was pulled in another direction for awhile but can get back to this. |
I've dug into this and clumsy handling of empty elements appears to be a "feature" of the libxml2 reader. See http://xmlsoft.org/xmlreader.html#Extracting Exposing IsEmptyElement via nokogiri would be a nice-to-have -- to know that an end element won't be in the pipeline for a given start element -- but empty elements can be identified by the depth of whatever follows the start element. So, exposing the IsEmptyElement is a wishlist item, but not a bug. |
Can you please write up a (failing) unit test expressing exactly what you'd like to see? Linking to a gist from this ticket would be perfect. |
I also believe this would be nice to have. http://stackoverflow.com/questions/2775307/nokogiri-pull-parser-nokogirixmlreader-issue-with-self-closing-tag . Basically, using the Reader#read method, i would like to know if i'm on a |
I'm glad everyone agrees this is a nice feature to have. High five! P.S. Can you please write up a (failing) unit test expressing exactly what you'd like to see? Linking to a gist from this ticket would be perfect. P.P.S. Srsly, peepul. Failing unit test. |
Awesome! Thank you. What would everyone think about making the method name be "empty?" instead of "empty_element?" ? The precedent is in Nokogiri::HTML::ElementDescription (as well as String, Array, Hash, etc.). Plus it means less typing. :) |
You're right. I'm OK with it. Q: because it's more generic, what will it return for other node types? (false or undefined?). EG |
Hum. Maybe we should go for a more semantic method name, like |
I second |
adding Reader#empty_element? and Reader#self_closing? closed by 52a2473 |
The Reader pull-parser doesn't expose a way to determine if an element is empty when there is no separate end tag (), since no end element is encountered (or synthesized). I presume some call to xmlTextReaderIsEmptyElement is in order.
The text was updated successfully, but these errors were encountered: