简体   繁体   中英

How to interpret Zero-Length XML Element Content?

Given an element with zero-length content <foo></foo> , is the textual value of foo "" or null ?

Does the answer depend on whether the containing document is being interpreted by some schema or other?

It is considered an empty string. There is no concept of "null" in XML. There is a "nil", which is specified as an attribute like:

<foo xsi:nil="true" />

There is also the option of simply omitting the element, which may be considered "null-like" to the consumer of the XML.

For example, JAXB marshals both "nil" and a missing element to a Java null , and you can configure how it behaves in the reverse scenario.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM