empty xml element spanning multiple lines

M

Mark

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
 
H

Hermann Peifer

Mark said:
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
 
P

Peter Flynn

Mark said:
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
 
M

Mark

Thanks everyone for your responses. I managed to convince them to have empty
elements on the one line.
 
H

Hermann Peifer

C. M. Sperberg-McQueen said:
[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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top