Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Ruby > Preventing "collapse" of HTML tags during XML parse

Reply
Thread Tools

Preventing "collapse" of HTML tags during XML parse

 
 
Rob Hunter
Guest
Posts: n/a
 
      08-30-2007
I'm trying to avoid having

<textarea id="foo"></textarea>

turn into

<textarea />

But this is exactly what happens to me in both XmlSimple and REXML:

irb(main):028:0> print
XmlSimple.xml_out(XmlSimple.xml_in("<opt><textarea id=\"foo\"></tex\
tarea></opt>"))
<opt>
<textarea id="foo" />
</opt>

The problem is that

<textarea />

doesn't render in a browser.

Does anyone know of a way to avoid this in either library? Or, should I
be doing this another way?

Thanks,
Rob
--
Posted via http://www.ruby-forum.com/.

 
Reply With Quote
 
 
 
 
Stefan Rusterholz
Guest
Posts: n/a
 
      08-30-2007
Rob Hunter wrote:
> I'm trying to avoid having
>
> <textarea id="foo"></textarea>
>
> turn into
>
> <textarea />
>
> But this is exactly what happens to me in both XmlSimple and REXML:
>
> irb(main):028:0> print
> XmlSimple.xml_out(XmlSimple.xml_in("<opt><textarea id=\"foo\"></tex\
> tarea></opt>"))
> <opt>
> <textarea id="foo" />
> </opt>
>
> The problem is that
>
> <textarea />
>
> doesn't render in a browser.
>
> Does anyone know of a way to avoid this in either library? Or, should I
> be doing this another way?
>
> Thanks,
> Rob


HTML is not an XML language, it is an SGML language. Use an HTML parser
instead of an XML parser. For example Hpricot.

Regards
Stefan
--
Posted via http://www.ruby-forum.com/.

 
Reply With Quote
 
 
 
 
Keith Fahlgren
Guest
Posts: n/a
 
      08-31-2007
On 8/30/07, Rob Hunter <(E-Mail Removed)> wrote:
> I'm trying to avoid having
>
> <textarea id="foo"></textarea>
>
> turn into
>
> <textarea />
>
> But this is exactly what happens to me in both XmlSimple and REXML:


<empty/> and <empty></empty> are equivalent in the XML spec, so this
is correct behavior.

> Does anyone know of a way to avoid this in either library? Or, should I
> be doing this another way?


If you're using REXML, you might investigate the last argument to write():

http://www.ruby-doc.org/stdlib/libdo...t.html#M002971

ie_hack: Internet Explorer is the worst piece of crap to have ever
been written, with the possible exception of Windows itself. Since IE
is unable to parse proper XML, we have to provide a hack to generate
XML that IE's limited abilities can handle. This hack inserts a space
before the /> on empty tags. Defaults to false


HTH,
Keith

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
All style tags after the first 30 style tags on an HTML page are not applied in Internet Explorer Rob Nicholson ASP .Net 3 05-28-2005 03:11 PM
How to parse a XML doc with HTML tags within the texts Francesco Moi XML 8 02-21-2005 01:40 PM
html tags within meta tags allowed? Donald Firesmith XML 5 01-08-2005 11:29 PM
RegEx to find CFML tags nested in HTML tags Dean H. Saxe Perl 0 01-03-2004 06:11 PM
parse inside of html tags jjliu Perl 3 10-11-2003 11:34 AM



Advertisments