Closed OgreSwamp closed 6 years ago
That is an interesting question... I totally understand what you're saying, too. There is conceptually a difference between <midname></midname>
and <midname />
. I'd have to research how other XML parsers treat that situation, whether one is an empty string or nil or not because I'd like to behave consistently there.
EDIT - that being said, I think that while those two options look different, they're treated by XML parsers the same.
Regarding why, the underlying reason is that XMLElement
's text
property is not nillable. See https://github.com/drmohundro/SWXMLHash/blob/master/Source/SWXMLHash.swift#L895-L903.
I think I'm going to pass on this feature - the parsers that I researched seem to treat empty elements as empty strings (versus null) aside from a few where you can optionally configure the NULL
string to become null. If there are enough other requests, I might reconsider this, though.
I have an XML where some elements can have no content, e.g.:
<midname>Paul</midname>
or<midname/>
if I'm parsing it with SWXMLHash to a
String?
I never get anil
as result. For<midname/>
case the parser returns an emptyString
.Example:
In
deserialize
method I wrote extra code to make sure optional has a nil value:But I think that should be done automatically? Would you agree?