When using Nokogiri, how do you suppress the insertion of self-closing tags?

My XML doc, which is the config file for a Jenkins job, has a lot of empty tags like:


which Nokogiri replaces with:


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?


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


  • Iterating through multiple URLs to parse HTML with Nokogori
  • Screen Scrapping with nokogiri
  • Parsing large HTML files with Nokogiri
  • Ruby: Alias a method from a class
  • Using sed to extract string values
  • looking for cleaner code when embedding razor calls in text
  • Add a div to replace Video after Video Plays Through
  • overlapping appointments using the entity framework
  • Should a C# struct have only read-only properties
  • Whats the best way of persisting data to Isolated Storage on Windows Phone 7?
  • What version of Java should I use with Cassandra 2.0?
  • MySQL multiple IN conditions to subquery with same table
  • Is it better to use the “hidden” CSS attribute or fetch each set of new images?
  • Is it possible to get the word under the mouse cursor in a ``?
  • hibernate sets dirty flag (and issues update) even though client did not change value
  • BeautifulSoup difference between findAll and findChildren
  • NHibernate manually control fetching
  • Email format validation in mvc3 view
  • C# - Is there a limit to the size of an httpWebRequest stream?
  • How to get a value (ex: baseURL) in every Karate feature?
  • How to add date and time under each post in guestbook in google app engine
  • Controls, properties, events and timers running in design time
  • Invalid access key error using credentials redeemed from an amazon open id token
  • AT Commands to Send SMS not working in Windows 8.1
  • Circular dependency while pushing http interceptor
  • jqPlot EnhancedLegendRenderer plugin does not toggle series for Pie charts
  • A cron job substitute?
  • Windows forms listbox.selecteditem displaying “System.Data.DataRowView” instead of actual value
  • InvalidAuthenticityToken between subdomains when logging in with Rails app
  • coudnt use logback because of log4j
  • How to get Windows thread pool to call class member function?
  • IndexOutOfRangeException on multidimensional array despite using GetLength check
  • apache spark aggregate function using min value
  • Sorting a 2D array using the second column C++
  • costura.fody for a dll that references another dll
  • Observable and ngFor in Angular 2
  • How to Embed XSL into XML
  • UserPrincipal.Current returns apppool on IIS
  • Conditional In-Line CSS for IE and Others?
  • java string with new operator and a literal