68

I have an xml and it has nodes with i:nil="true" in it. What does that mean?

For example:

<FirstName i:nil="true" />

Does that mean something different than:

<FirstName />

If so, what is the difference?

James A Mohler
  • 11,060
  • 15
  • 46
  • 72
dtc
  • 10,136
  • 16
  • 78
  • 104

3 Answers3

113

This means FirstName is null

<FirstName i:nil="true" />

This means FirstName = ""

<FirstName />

Assumption made on FirstName is of string type.

Ray Lu
  • 26,208
  • 12
  • 60
  • 59
  • 4
    According to which standard? If FirstName was "", the document would be , which is not the same as (the former is not canonicalized to the latter.) – Torsten Marek Jan 21 '09 at 11:58
  • 17
  • 6
    "The representation of an empty element is either a start-tag immediately followed by an end-tag, or an empty-element tag." - http://www.w3.org/TR/REC-xml/#sec-starttags | of course, that has nothing to do with equating `` to mean "the value of the FirstName field is the empty string." There is no "standard" for that...it is dependent on whatever XML serialization tool you are using, but most tools generally behave the same. – Dr. Wily's Apprentice Apr 04 '12 at 16:15
14

Maybe i:nil actually means xsi:nil, this means that the FirstName element is empty, i.e. does not have any content -- not even "". It refers to the nillable property in XML Schema.

Torsten Marek
  • 83,780
  • 21
  • 91
  • 98
  • 10
    `xsi` has no meaning by itself. It's just a namespace prefix. Most likely, it is defined as the same thing that `xsi` is usually defined as: `http://www.w3.org/2001/XMLSchema-instance` – John Saunders Jan 15 '13 at 02:18
5

nil is an attribute, defined in the i namespace. For this FirstName node, the attribute has the value true.

It's similar to this, just with different names and values:

<form name="test">...

Here, form is the name of the node, similar to FirstName from your code, and name is an attribute with a value of "test", similar to your attribute nil with a value of "true".

What this means depends on the application reading the xml document.

If I were to venture a guess, I'd say that this looks like part of a xml document defining some kind of schema, and that the FirstName field can have a NULL or nil value, meaning empty, or unknown.

Lasse V. Karlsen
  • 380,855
  • 102
  • 628
  • 825