I have a problem like What's the cleanest way to ignore empty nodes with Nokogiri::XML::Builder , except that my XML document is generated by a .builder template file using the builder gem.
I'm generating an XML document using the builder gem (and tilt) and I want to get rid of empty nodes.
The answer suggesting just iterating through each attribute and deciding whether to serialise each attribute or not isn't very suitable to my application, because there's quite a lot of logic involved in building the XML document.
The answer suggesting the use of Nokogiri::XML::Node#traverse
doesn't look bad, but I suspect this approach isn't supported by the builder gem. The documentation for builder says
An
Builder::XmlTree
class to generate XML tree (i.e. DOM-like) structures is also planned, but not yet implemented. Also, the events builder is currently lagging the markup builder in features.
(I'm not sure if the quoted section is equivalent to Nokogiri::XML::Node#traverse
, but it does at the least suggest that there's some functionality not available in Builder)
Also, searching for some sort of remove method doesn't get a match in the git repository.
The builder gem, as of 2017, is largely abandoned. The master branch last had a commit in June 2013, and there's only been a handful of commits in forks since then. Tilt's mention of maintenance only refers to the maintenance of integration between tilt and builder.
Are there any gems that support the .builder
format other than the builder gem?
Do I have any alternatives other than adding a lot of if title
or if feed
conditionals to the .builder
file, or once I've created the XML, feeding it through an unrelated XML parser?