ruby - How can I make empty tags self-closing with Nokogiri? -


I have created an XML template in the ERB, I fill it with data from a database during an export process.

In some cases, there is a zero value in which an element can be empty, such as:

    

In that case, the customer seeking the export wants to change it to a self-closing tag:

  & lt; Someitem / & gt;   

I am trying to see how to get a job to do this, but I do not see it yet. Does anyone know how to make empty XML tags self-closing with Nokogiri?

Update

A regedge I specified above was enough, but the client still wants to tag the ones whose children are all empty to conclude themselves: / P>

... must also be

    

I think it will require the use of the nokia.

search

    

and

  & lt; \ 1 / & gt;   

In Ruby:

  results = subject. Gsub (/ & lt; ([^ & gt;] +) & gt; \ s * & lt; \ / <1    
  & lt; # Matching opening bracket (# matches and remembering ... [^> one or more characters except for ##] * # capturing group & gt; # matching closing bracket \ s * # Optional optional peaks Match & amp; Newline and LT; # Matching Bracket / # Match / \ # Match the contents of the opening tag & gt; # Match Closing Bracket    

Comments