Empty Elements in XHTML

Discussion in 'XML' started by August Karlstrom, Mar 11, 2007.

  1. Hi everyone,

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

    Example:

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


    Regards,

    August
     
    August Karlstrom, Mar 11, 2007
    #1
    1. Advertising

  2. August Karlstrom wrote:

    > In XHTML, can any empty element <foo></foo> be 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 interoperability, 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></td> and only elements defined as being empty (such
    as the br element) as <br />.

    --

    Martin Honnen
    http://JavaScript.FAQTs.com/
     
    Martin Honnen, Mar 11, 2007
    #2
    1. Advertising

  3. Martin Honnen skrev:
    > August Karlstrom wrote:
    >
    >> In XHTML, can any empty element <foo></foo> be 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 interoperability, 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></td> and only elements defined as being empty (such
    > as the br element) as <br />.
    >


    OK, thanks for the accurate answer.


    August
     
    August Karlstrom, Mar 11, 2007
    #3
  4. August Karlstrom

    Andy Dingley Guest

    On 11 Mar, 16:14, August Karlstrom <> wrote:

    > In XHTML, can any empty element <foo></foo> be 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>, <hr> etc.) 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.
     
    Andy Dingley, Mar 12, 2007
    #4
    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. Mark
    Replies:
    7
    Views:
    571
  2. Mikko Ohtamaa
    Replies:
    13
    Views:
    696
    Jukka K. Korpela
    Sep 2, 2003
  3. Lukas
    Replies:
    3
    Views:
    817
    spiff
    Nov 10, 2005
  4. Replies:
    7
    Views:
    903
  5. chronos3d
    Replies:
    9
    Views:
    787
    Andy Dingley
    Dec 5, 2006
Loading...

Share This Page