Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can an XML attribute be the empty string?

Tags:

xml

Can an XML attribute be the empty string?

In other words, is

<element att="" />

valid XML?

like image 638
David Locke Avatar asked Oct 08 '08 18:10

David Locke


People also ask

Can XML attributes be empty?

Empty XML Elements 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.

Is empty string a valid XML?

It's not valid xml, but it can be inserted into an XML column in SQL Server 2005.

How do I create an empty string in XML?

Ensure that the tag (e.g. %%middlename%%) contains the value null. In your message action (e.g. Publish) right click the "text (String) {XML}" node and select "Properties". Set the check box "Send NULL values". Your message action should now send an XML nil as the node value.

Can XML have NULL values?

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.


4 Answers

Yes, this is well-formed XML.

An easy way to test this (on Windows) is to save the sample in a test.xml file and open it with Internet Explorer. IE will display an error message if the document is not well-formed.

like image 106
Bradley Grainger Avatar answered Sep 27 '22 16:09

Bradley Grainger


You can create an empty attribute via attname=""

You can create an empty element via

<elementName></elementName>

or

<elementName/>
like image 26
Mitchel Sellers Avatar answered Sep 27 '22 15:09

Mitchel Sellers


It is worth nothing that this is an XML attribute, not an element. An empty element would be:

</>

which is not valid XML.

like image 35
Greg Hewgill Avatar answered Sep 27 '22 17:09

Greg Hewgill


this is valid xml tag:

<mytag myattrib=""/>

this is not:

<mytag myattrib/>
like image 27
coder Avatar answered Sep 27 '22 17:09

coder