design difference between xml & html

Discussion in 'XML' started by Ankit, Dec 25, 2004.

  1. Ankit

    Ankit Guest

    Hi
    This is what I beleive. Please tell whether this is true.

    Is it true that in xml we can have no text belonging to an element that
    has sub elements too?
    While in HTML this can be.

    for eg.

    <parent>
    parent data
    <child>
    child data
    </child>
    </parent>

    is the above valid XML ?
    Thanks
    Ankit Jain
    Ankit, Dec 25, 2004
    #1
    1. Advertising

  2. Ankit

    Arjun Ray Guest

    On Fri, 24 Dec 2004 22:29:14 -0800, Ankit wrote:

    > Is it true that in xml we can have no text belonging to an element that
    > has sub elements too?


    No, it is not true.

    You should read the XML spec. The latest edition is at

    http://www.w3.org/TR/2004/REC-xml-20040204/

    Look at Section 3.2.2 "Mixed Content".
    Arjun Ray, Dec 25, 2004
    #2
    1. Advertising

  3. Ankit wrote:


    > Is it true that in xml we can have no text belonging to an element that
    > has sub elements too?
    > While in HTML this can be.
    >
    > for eg.
    >
    > <parent>
    > parent data
    > <child>
    > child data
    > </child>
    > </parent>
    >
    > is the above valid XML ?


    You can only talk about validity of a certain XML document if you also
    provide or refer to a grammar in form of a DTD or a schema which should
    be used to validate the XML against it.
    It is possible to write a DTD that allows that XML so that the XML is
    valid according to the DTD but it is also possible to write a DTD so
    that the XML is not valid according to that DTD.

    If you are only asking about the well-formedness of that XML above then
    yes, it is well-formed, you were only pointed to the relevant section in
    the XML specification talking about mixed content.

    And depending on which HTML 4 DTD for instance you use you will also
    find elements whose content model is restricted to child elements while
    it doesn't allow text child nodes so your understanding of HTML seems
    not to be right too.

    --

    Martin Honnen
    http://JavaScript.FAQTs.com/
    Martin Honnen, Dec 25, 2004
    #3
  4. Ankit

    Peter Flynn Guest

    Ankit wrote:

    > Hi
    > This is what I beleive. Please tell whether this is true.
    >
    > Is it true that in xml we can have no text belonging to an element that
    > has sub elements too?


    No, this is false. It's called Mixed Content and it is extremely common in
    normal text documents in (for example) paragraphs.

    > While in HTML this can be.


    Yes, exactly like HTML.

    > for eg.
    >
    > <parent>
    > parent data
    > <child>
    > child data
    > </child>
    > </parent>


    This is poor design. It would be better as

    <parent>parent data<child>child data</child></parent>

    and only insert spaces where you really need them. Mixed Content in non-text
    applications ("data" XML) is very rare and probably an error.

    > is the above valid XML ?


    Only if you have a DTD or Schema which specifies that structure.

    ///Peter
    --
    "The cat in the box is both a wave and a particle"
    -- Terry Pratchett, introducing quantum physics in _The Authentic Cat_
    Peter Flynn, Dec 31, 2004
    #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. jakk
    Replies:
    4
    Views:
    12,139
  2. Santa
    Replies:
    1
    Views:
    1,074
    Mark A. Odell
    Jul 17, 2003
  3. arnuld
    Replies:
    33
    Views:
    1,182
  4. PerlFAQ Server
    Replies:
    0
    Views:
    355
    PerlFAQ Server
    Jan 6, 2011
  5. PerlFAQ Server
    Replies:
    0
    Views:
    260
    PerlFAQ Server
    Apr 15, 2011
Loading...

Share This Page