Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > XML > empty xml element spanning multiple lines

Reply
Thread Tools

empty xml element spanning multiple lines

 
 
Mark
Guest
Posts: n/a
 
      03-23-2009
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
 
Reply With Quote
 
 
 
 
Hermann Peifer
Guest
Posts: n/a
 
      03-23-2009
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
 
Reply With Quote
 
 
 
 
Peter Flynn
Guest
Posts: n/a
 
      03-23-2009
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
 
Reply With Quote
 
Mark
Guest
Posts: n/a
 
      03-24-2009
Thanks everyone for your responses. I managed to convince them to have empty
elements on the one line.
 
Reply With Quote
 
Hermann Peifer
Guest
Posts: n/a
 
      03-27-2009
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
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
how to Update/insert an xml element's text----> (<element>text</element>) HANM XML 2 01-29-2008 03:31 PM
Syntax for variable names spanning multiple lines in C Sriram Rajagopalan C Programming 28 11-16-2006 09:24 AM
Altova Mapforce - xml 2 xml map: empty elements output although input element is not empty Lukas XML 3 11-10-2005 02:25 PM
print statement spanning multiple lines Voitec Perl Misc 9 11-13-2003 02:03 AM
Spanning Tree And Per Vlan Spanning Tree Amy L. Cisco 0 07-24-2003 10:01 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57