Skip to content
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

Closed
jfieber opened this issue Apr 22, 2010 · 13 comments
Closed

Detecting empty elements with XML::Reader #262

jfieber opened this issue Apr 22, 2010 · 13 comments

Comments

@jfieber
Copy link

jfieber commented Apr 22, 2010

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.

@flavorjones
Copy link
Member

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.

@flavorjones
Copy link
Member

Ping: jflieber -- is this still needed?

@jfieber
Copy link
Author

jfieber commented May 4, 2010

Yes, I was pulled in another direction for awhile but can get back to this.

@jfieber
Copy link
Author

jfieber commented May 4, 2010

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.

@flavorjones
Copy link
Member

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.

@vladzloteanu
Copy link

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 <tag> or on a <tag/> node.

@flavorjones
Copy link
Member

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.

@vladzloteanu
Copy link

@flavorjones
Copy link
Member

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. :)

@vladzloteanu
Copy link

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 </tag> is empty?

@flavorjones
Copy link
Member

Hum. Maybe we should go for a more semantic method name, like self_closing??

@johndouthat
Copy link

I second self_closing? .

@tenderlove
Copy link
Member

adding Reader#empty_element? and Reader#self_closing? closed by 52a2473

This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants