empty xml element spanning multiple lines

Discussion in 'XML' started by Mark, Mar 23, 2009.

  1. Mark

    Mark Guest

    I've working on processing xml from an external source (who I can contact to
    change things if they turn out to be incorrect) and in their xml documents empty
    elements span multiple lines e.g.

    <element>
    </element>

    rather than <element /> or <element></element>. When I'm parsing the xml the
    text of the element is '\n' which is what I would expect, but not what they
    intend - it should be null or an empty string or whatever. Is what they're doing
    wrong in expressing an empty element, or is it simply ugly (but not wrong)?

    TIA
    Mark, Mar 23, 2009
    #1
    1. Advertising

  2. Mark wrote:
    > I've working on processing xml from an external source (who I can
    > contact to change things if they turn out to be incorrect) and in their
    > xml documents empty elements span multiple lines e.g.
    >
    > <element>
    > </element>
    >
    > rather than <element /> or <element></element>. When I'm parsing the xml
    > the text of the element is '\n' which is what I would expect, but not
    > what they intend - it should be null or an empty string or whatever. Is
    > what they're doing wrong in expressing an empty element, or is it simply
    > ugly (but not wrong)?
    >
    > TIA


    As you noticed: the "empty" elements are obviously not empty. If the data provider's intention was to provide a true empty element, then the only options are <element /> or <element></element>, anything else would be wrong.

    Hermann
    Hermann Peifer, Mar 23, 2009
    #2
    1. Advertising

  3. Mark

    Peter Flynn Guest

    Mark wrote:
    > I've working on processing xml from an external source (who I can
    > contact to change things if they turn out to be incorrect) and in their
    > xml documents empty elements span multiple lines e.g.
    >
    > <element>
    > </element>
    >
    > rather than <element /> or <element></element>.


    As you observe, that isn't an empty element. It contains at least a
    newline character.

    > When I'm parsing the xml
    > the text of the element is '\n' which is what I would expect, but not
    > what they intend - it should be null or an empty string or whatever. Is
    > what they're doing wrong in expressing an empty element, or is it simply
    > ugly (but not wrong)?


    Not ugly, IMHO, but certainly wrong if they believe it means "empty",
    and a very common misunderstanding by people who haven't understood
    markup. It's easily overcome in the processing, but it's bad practice,
    and symptomatic of the file being generated by someone who is just doing
    what their imagination wants to see, rather than what is required. I
    find this occurs rather frequently among programmers and database
    engineers moved in from unrelated projects, because of the assumption
    that XML contains "fields". A similar hallmark to watch out for is the
    use of pretty-printing of elements containing text, eg

    <element>
    This is the content.
    </element>

    which contains superfluous newlines and other white-space.

    ///Peter
    Peter Flynn, Mar 23, 2009
    #3
  4. Mark

    Mark Guest

    Thanks everyone for your responses. I managed to convince them to have empty
    elements on the one line.
    Mark, Mar 24, 2009
    #4
  5. C. M. Sperberg-McQueen wrote:
    >
    > [Pedantry alert]. Well, 'only' may be a bit strong.
    > There are also forms like <element
    >> </element> and <element

    >
    >
    >
    >
    > /> -- unlikely to matter to the OP or the data source,
    > but not to be overlooked by a parser.
    >


    From the OP's type of question, I concluded that he would perhaps not be too much interested in these details.

    Just to add yet another variant: one could also use <element/> if one wants to save (rather than add) some whitespace.

    Hermann
    Hermann Peifer, Mar 27, 2009
    #5
    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. Lukas
    Replies:
    3
    Views:
    778
    spiff
    Nov 10, 2005
  2. Sriram Rajagopalan

    Syntax for variable names spanning multiple lines in C

    Sriram Rajagopalan, Nov 13, 2006, in forum: C Programming
    Replies:
    28
    Views:
    816
    Richard Bos
    Nov 16, 2006
  3. pbd22
    Replies:
    0
    Views:
    282
    pbd22
    Nov 18, 2007
  4. Jamie Jackson

    Spanning Lines & Dynamic Pattern Matching

    Jamie Jackson, Oct 25, 2004, in forum: Javascript
    Replies:
    5
    Views:
    90
    Jamie Jackson
    Oct 26, 2004
  5. Voitec
    Replies:
    9
    Views:
    224
    Iain Chalmers
    Nov 13, 2003
Loading...

Share This Page