问题
My XML doc, which is the config file for a Jenkins job, has a lot of empty tags like:
<string></string>
which Nokogiri replaces with:
<string/>
While this is the "recommended" way to write XML, it ends up generating unnecessary changes to the XML that make it difficult to read the meaningful content changes. Is there a way to suppress this behavior?
回答1:
You can use the NO_EMPTY_TAGS option:
doc.to_xml(:save_with => Nokogiri::XML::Node::SaveOptions::NO_EMPTY_TAGS)
or the rather more concise:
doc.to_xml &:no_empty_tags
来源:https://stackoverflow.com/questions/26416406/when-using-nokogiri-how-do-you-suppress-the-insertion-of-self-closing-tags