[XML-DEV Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] RE: Occurrence Question
--- "Tolkin, Steve" <Steve.Tolkin@F...> ha scritto: > Can you please clarify what you meant by "there is > no difference between > empty and absent in xml." Yes sure, I can try, I have various thoughts on the argument, I put them out. xml tree is made mainly of sequences of nodes, these sequences can be empty or filled but there is no third option (null or absent) in this construct. In DOM child nodes are a Node*List* that is always present,by default empty. The difference between null and empty is common in programming languages and databases. An object and a record can be seen as a map, an associative array, one gets the values from it by name. The children of an xml element are a single sequence containing items with possibly different names, is very different from an object or a record. A text field of a DB record can usually be null or an empty string, an object field value might be null if the language uses strings as references, like in java. In Basic there is no null string, some Basic use a placeholder for communicating with databases. XML attributes are different because they are not a sequence but more like a map (in DOM a NamedNode*Map*) and one can distinguish between the three cases for attribute b: <a> <a b=''> <a b='ccccc'> An attribute can be used more easily to serialize the null value of a field, but there are some differences. In a map it might be possible to distinguish between an entry {key,value} with null value and an absent entry, this might be relevant when merging maps (as happens for DB updates) Something like this is (luckily?) not present in xml. <a b='<null/>'/> When there is this empty/null difference there _might_ be three states for a 'value': null/empty/present or even 4 considering [absent] and [present but null] as different. This last possibility is only in open maps, not in objects or records where the keys are fixed. xml elements 'collections' and xml text content cannot be mapped to a null or an 'empty value' consistently, you need to choose one of the two possibly helping yourself with some other info. Text of an element does not really exists as property of an xml element, in DOM might be seen as the the sum of the node values of the child nodes of type text if there are no child elements. Also 'collections' do not exist, there is only one sequence, the sequence of the child nodes, you need to interpret the sequence iterating it and selecting the right nodes to be put in a collection, you cannot just say "give me a certain collection" as with objects. > I think there is a difference. Suppose the empty > element <Bonus> is > used as a "marker", meaning: If and only if <Bonus/> > occurs then the > person is eligible to receive a bonus. > Clearly there is a difference between empty and > absent. Yes but there is no third option. In your example the element is present: is the content, the child nodes sequence, to be empty. The other case is the absent element. If the bonus is a boolean primitive (true/false) then an element absent/present might be a good marker. But a boolean could be also a java.lang.Boolean allowing null value, or a boolean field of a DB record, also allowing null value. The null value might mean that the bonus-situation has not been decided yet or might be used to unset a true/false situation. If one doesn't have nulls might use two values or create an enumeration, use xsi:nil [1] or other trick. In general one needs a convention so that is pssible to interpret the xml data and reproduce this concept and you cannot just 'read it' from the data. in my opinion the absence of a difference between null an empty and also the absence of an explicitly serialized container for collections gives big advantages in compatibility between _serialized instances of objects_ since the same serialized form can be 'interpreted' as an instance of different structures. For example one single element can be a single occurrence field but also the first item of a future collection. So for me using xml for object serialization is better than binary for compatibility, what is not good instead is using xml or xml schema to describe objects, beacause some structures cannot be mapped. Greetings Michele [1] http://www.w3.org/TR/xmlschema-1/#xsi_nil http://xsd.stylusstudio.com/2001Nov/post02006.htm ___________________________________ Yahoo! Messenger with Voice: chiama da PC a telefono a tariffe esclusive http://it.messenger.yahoo.com
|
PURCHASE STYLUS STUDIO ONLINE TODAY!Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced! Download The World's Best XML IDE!Accelerate XML development with our award-winning XML IDE - Download a free trial today! Subscribe in XML format
|