Skip to content

Instantly share code, notes, and snippets.

@sbecker
Created March 30, 2009 23:58
Show Gist options
  • Save sbecker/87961 to your computer and use it in GitHub Desktop.
Save sbecker/87961 to your computer and use it in GitHub Desktop.
# issue I'm having with Hpricot 0.7.232 (latest build I believe).
# So to be specific, inside a tag named "description" it seems to behave wrong, with .text returning all of the text in the XML from that point forward.
# If I change the name of the parent tag to anything else, it works right, returning just the text inside the tag. Weird eh? Here is some code, hopefully it formats in a readable way:
# Inside of a tag called 'description' - gives incorrect .text value: "test\n one,two\n"
>> xml = Hpricot.XML(%{
<peon>
<id>1</id>
<description>test</description>
<tags>one,two</tags>
</peon>})
=> #<Hpricot::Doc "\n" {elem <peon> "\n " {elem <id> "1" </id>} "\n " {elem <description> "test" {bogusetag </description>} "\n " {elem <tags> "one,two" {bogusetag </tags>} "\n" {bogusetag </peon>}}}}>
>> (xml/:peon/:description).text
=> "test\n one,two\n"
# Inside of a tag called something else, in this case 'descriptiona' - gives correct .text value: "test"
>> xml = Hpricot.XML(%{
<peon>
<id>1</id>
<descriptiona>test</descriptiona>
<tags>one,two</tags>
</peon>})
=> #<Hpricot::Doc "\n" {elem <peon> "\n " {elem <id> "1" </id>} "\n " {elem <descriptiona> "test" </descriptiona>} "\n " {elem <tags> "one,two" {bogusetag </tags>} "\n" {bogusetag </peon>}}}>
>> (xml/:peon/:descriptiona).text
=> "test"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment