Empty Elements in XHTML

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • August Karlstrom

    Empty Elements in XHTML

    Hi everyone,

    In XHTML, can any empty element <foo></foobe replaced by <foo />?

    Example:

    <table>
    <tr><td>1</td><td>2</td></tr>
    <tr><td /><td>4</td></tr>
    </table>


    Regards,

    August
  • Martin Honnen

    #2
    Re: Empty Elements in XHTML

    August Karlstrom wrote:
    In XHTML, can any empty element <foo></foobe replaced by <foo />?
    >
    Example:
    >
    <table>
    <tr><td>1</td><td>2</td></tr>
    <tr><td /><td>4</td></tr>
    </table>
    If parsed as XML it will not matter whether you have
    <td></td>
    or
    <td />
    or
    <td/>

    On the other hand the XML 1.0 specification says
    "For interoperabilit y, the empty-element tag SHOULD be used, and
    SHOULD only be used, for elements which are declared EMPTY."
    so as td elements are not declared as empty".
    That is also what the XHTML 1.0 specification suggests if you want to
    serve XHTML 1.0 documents as text/html. In that case you markup an empty
    table cell as <td></tdand only elements defined as being empty (such
    as the br element) as <br />.

    --

    Martin Honnen

    Comment

    • August Karlstrom

      #3
      Re: Empty Elements in XHTML

      Martin Honnen skrev:
      August Karlstrom wrote:
      >
      >In XHTML, can any empty element <foo></foobe replaced by <foo />?
      >>
      >Example:
      >>
      ><table>
      > <tr><td>1</td><td>2</td></tr>
      > <tr><td /><td>4</td></tr>
      ></table>
      >
      If parsed as XML it will not matter whether you have
      <td></td>
      or
      <td />
      or
      <td/>
      >
      On the other hand the XML 1.0 specification says
      "For interoperabilit y, the empty-element tag SHOULD be used, and
      SHOULD only be used, for elements which are declared EMPTY."
      so as td elements are not declared as empty".
      That is also what the XHTML 1.0 specification suggests if you want to
      serve XHTML 1.0 documents as text/html. In that case you markup an empty
      table cell as <td></tdand only elements defined as being empty (such
      as the br element) as <br />.
      >
      OK, thanks for the accurate answer.


      August

      Comment

      • Andy Dingley

        #4
        Re: Empty Elements in XHTML

        On 11 Mar, 16:14, August Karlstrom <fusionf...@com hem.sewrote:
        In XHTML, can any empty element <foo></foobe replaced by <foo />?
        What's "XHTML" here?

        If you mean "XHTML as XML", then of course they're absolutely
        identical. However you can't use XHTML as XML on today's web (an FAQ
        in c.i.w.a.h)

        if you mean "Appendix C XHTML" so as to make it usable on the web,
        then they're different and must be kept distinct. XML sees "empty
        elements" as those with no current content at that time. HTML sees
        "empty elements" as those defined as empty in ther DTD (e.g. <img>,
        <br>, <hretc.) These _defined_ empty elements should be serialised
        as <br /but non-empty elements with no content must remain as start
        and end tags, e.g. <script src="foo.js" ></script>

        There's a huge amount of past discussion of this in c.i.w.a.h, some of
        it's even accurate.

        Comment

        Working...