I'm a total hpricot newbie, so this is only out of curiousity...
Is the following expected behaviour?
I found this while struggling through a nasty xml parsing bug.
hstr = Hpricot('<a/><b>c</b>').to_s #or to_html
returns => '<a><b>c</b></a>'
I have found that using to_original_html returns '<a/><b>c</b>' as expected
but I was wondering why you would want <a/> to wrap the other contents when
it obviously isn't correct? Is this handy behaviour for scrapping?
regards
Hmm... if you want modern markup, it is correct.
<a href="some_uri" title="some_title">Link's text here</a>
You'd do well to avoid <b></b> in favor of <strong></strong>
···
On Jul 19, 2007, at 1:32 AM, Ivor Paul wrote:
I'm a total hpricot newbie, so this is only out of curiousity...
Is the following expected behaviour?
I found this while struggling through a nasty xml parsing bug.
hstr = Hpricot('<a/><b>c</b>').to_s #or to_html
returns => '<a><b>c</b></a>'
I have found that using to_original_html returns '<a/><b>c</b>' as expected
but I was wondering why you would want <a/> to wrap the other contents when
it obviously isn't correct? Is this handy behaviour for scrapping?
regards
Yeah, I never understand that either. But it's easily fixed:
h = Hpricot('<a/><b>c</b>', :xml => true)
h.to_s => "<a></a><b>c</b>"
I think it's because when you don't define :xml as true, then Hpricot
acts as an *HTML* processor, and therefore tries to correct bad HTML..
and somehow ends up with the badness of wrapping the empty element.
Cheers,
Peter Cooper
···
On 7/19/07, Ivor Paul <ivorpaul@gmail.com> wrote:
I'm a total hpricot newbie, so this is only out of curiousity...
Is the following expected behaviour?
I found this while struggling through a nasty xml parsing bug.
hstr = Hpricot('<a/><b>c</b>').to_s #or to_html
returns => '<a><b>c</b></a>'
I have found that using to_original_html returns '<a/><b>c</b>' as expected
but I was wondering why you would want <a/> to wrap the other contents when
it obviously isn't correct? Is this handy behaviour for scrapping?
Thanks peter - that is what I wanted to hear! I knew there was some reason
like that.
···
On 7/19/07, Peter Cooper <peter@peterc.org> wrote:
On 7/19/07, Ivor Paul <ivorpaul@gmail.com> wrote:
> I'm a total hpricot newbie, so this is only out of curiousity...
>
> Is the following expected behaviour?
> I found this while struggling through a nasty xml parsing bug.
>
> hstr = Hpricot('<a/><b>c</b>').to_s #or to_html
>
> returns => '<a><b>c</b></a>'
>
> I have found that using to_original_html returns '<a/><b>c</b>' as
expected
> but I was wondering why you would want <a/> to wrap the other contents
when
> it obviously isn't correct? Is this handy behaviour for scrapping?
Yeah, I never understand that either. But it's easily fixed:
h = Hpricot('<a/><b>c</b>', :xml => true)
h.to_s => "<a></a><b>c</b>"
I think it's because when you don't define :xml as true, then Hpricot
acts as an *HTML* processor, and therefore tries to correct bad HTML..
and somehow ends up with the badness of wrapping the empty element.
Cheers,
Peter Cooper
http://www.rubyinside.com/