Preventing "collapse" of HTML tags during XML parse

Discussion in 'Ruby' started by Rob Hunter, Aug 30, 2007.

  1. Rob Hunter

    Rob Hunter Guest

    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/.
    Rob Hunter, Aug 30, 2007
    #1
    1. Advertising

  2. 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/.
    Stefan Rusterholz, Aug 30, 2007
    #2
    1. Advertising

  3. On 8/30/07, 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:


    <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/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
    Keith Fahlgren, Aug 31, 2007
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Vaclav Jedlicka

    datagrid and border-collapse:collapse style

    Vaclav Jedlicka, Jun 26, 2003, in forum: ASP .Net
    Replies:
    1
    Views:
    5,900
    Yan-Hong Huang[MSFT]
    Jun 30, 2003
  2. Francesco Moi
    Replies:
    8
    Views:
    556
    Martin Honnen
    Feb 21, 2005
  3. VVSRKS

    How can I avoid border-collapse:collapse to come ...

    VVSRKS, Sep 16, 2004, in forum: ASP .Net Datagrid Control
    Replies:
    0
    Views:
    187
    VVSRKS
    Sep 16, 2004
  4. Tom Castiglia

    Why does Gridview ALWAYS emit style="border-collapse: collapse;"

    Tom Castiglia, Jun 4, 2006, in forum: ASP .Net Web Controls
    Replies:
    2
    Views:
    1,935
    Tom Castiglia
    Jun 9, 2006
  5. M.L.
    Replies:
    9
    Views:
    285
Loading...

Share This Page