Preventing "collapse" of HTML tags during XML parse

R

Rob Hunter

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
 
S

Stefan Rusterholz

Rob said:
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
 
K

Keith Fahlgren

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:

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/libdoc/rexml/rdoc/classes/REXML/Element.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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,537
Members
45,022
Latest member
MaybelleMa

Latest Threads

Top