Possible Duplicate:
What is the correct way to represent null XML elements?
Is there a standard way to represent null attribute values in XML?
We have an existing XML format that expects fragments similar to:
<items>
<item key="key_goes_here" value="value_goes_here" />
...
</items>
The original format didn't anticipate the need to distinguish between a null value and an empty string value -- however, that is important (now).
My gut says to create a new format that avoids attributes for nullable values, and use elements for them instead:
<items>
<item key="key_goes_here_and_is_never_null">
<value xsi:nil="true" />
</item>
</items>
That said, I'd rather keep attributes if there's a standard way to represent null attribute values in XML.
In an XML document, the usual way to represent a null value is to leave the element or attribute empty. Some business messages use a special value to represent a null value: <price>-999</price> . This style of null representation is supported by the DFDL and MRM parsers.
An attribute element is used without any quotation and the attribute value is used in a single (' ') or double quotation (” “). An attribute name and its value should always appear in pair. An attribute value should not contain direct or indirect entity references to external entities.
The most explicit way to represent a null value in XML is to include an empty tag set for the data item.
An element with no content is said to be empty. The two forms produce identical results in XML software (Readers, Parsers, Browsers). Empty elements can have attributes.
I don't know about any standard, but how about using
<item key="key" />
for items that don't have a value,
<item key="key">
<value />
</item>
for items that have an empty string as a value and
<item key="key">
<value>This is the value</value>
</item>
for items that actually have a value?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With