0

Let's say this is the location element: <.location>blah...<./location>

It can be empty like this: <.location/>

Is there a way to detect the backslash in the empty element in order to not return it?

GEOCHET
  • 21,119
  • 15
  • 74
  • 98
Ben
  • 5,030
  • 6
  • 53
  • 94

2 Answers2

1

If what you really want is the text inside location tags, you can find those easily with the right XPath:

doc.search('//location/text()')

If, for some reason, you actually need the location element itself, use this:

doc.search('//location/text()/..')
Pesto
  • 23,810
  • 2
  • 71
  • 76
  • big thanks it'll be fixed this way, enough. in fact, reading the xml from my browser, it actually displays a <.location/>, but hpricot just reopen the tag and enclose the rest of the doc; hence the problem. – Ben Nov 04 '09 at 15:43
0

<location/> is semantically identical to <location></location>, and should be treated as such. To find all empty tags, just skip elements which do not have any child nodes (including text).

  • To be consise, this flickr api method is concerned : http://www.flickr.com/services/api/flickr.people.getInfo.html. When .. is empty, hpricot returns it like if it was getting something like ......etc..., in words as if location was enclosing more than it should be. From a browser you just can see that flickr is returning . Very confusing. – Ben Nov 05 '09 at 11:54