ROXML is a module for binding Ruby classes to XML. It supports custom mapping and bidirectional marshalling between Ruby and XML using annotation-style class methods, via Nokogiri or LibXML.
I had second thoughts on the previous change I made, where I added the :empty option. I've now just placed the same functionality I intended with :empty in to the existing :else option.
I've duplicated my original pull request comments (for :empty) here as reference:
As you know, the :else options is useful when an element is not in the XML at all. For example:
I've changed the :else option to handle situations where the XML is something like this:
<person>
<name />
</person>
As you can see, the element is there, it just has no content, which is different to the previous example. In the second example, ROXML would return name as nil.
So, for the above examples, if you have the following:
xml_accessor :name, :else => "None given"
The value for :name will be "None given" in the cases where the element is not in the XML at all, or when it's there, but empty, e.g. ""
I needed this because I had numerous places where I was checking for nil? The XML that I was consuming had many elements with no content. Now I can avoid those nil? checks.
I had second thoughts on the previous change I made, where I added the :empty option. I've now just placed the same functionality I intended with :empty in to the existing :else option.
I've duplicated my original pull request comments (for :empty) here as reference:
As you know, the :else options is useful when an element is not in the XML at all. For example:
I've changed the :else option to handle situations where the XML is something like this:
As you can see, the element is there, it just has no content, which is different to the previous example. In the second example, ROXML would return name as nil.
So, for the above examples, if you have the following:
The value for :name will be "None given" in the cases where the element is not in the XML at all, or when it's there, but empty, e.g. " "
I needed this because I had numerous places where I was checking for nil? The XML that I was consuming had many elements with no content. Now I can avoid those nil? checks.