Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>It's not ideal, but you can manually append close tags (or anything else, really) to an XmlBuilder instance using &lt;&lt;. It sounds like you're looking for something like this:</p> <pre><code>xml = Builder::XmlMarkup.new xml.outer do begin xml.inner do xml.text "content" raise "your hands" end rescue xml &lt;&lt; "&lt;/inner&gt;" end end </code></pre> <p>Because the rescue inserts the <code>&lt;/inner&gt;</code> tag, you'll get an output like this:</p> <pre><code>"&lt;outer&gt;&lt;inner&gt;&lt;text&gt;content&lt;/text&gt;&lt;/inner&gt;&lt;/outer&gt;" </code></pre> <h2>UPDATE</h2> <p>Ah, based on your comment, then, you're looking for something using nested XmlMarkups. Try this:</p> <pre><code>outside_xml = Builder::XmlMarkup.new outside_xml.outer do begin # Declare a string to use as a buffer buffer = '' # Create a separate XmlMarkup builder that writes to the buffer inside_xml = Builder::XmlMarkup.new(target: buffer) inside_xml.inner do inside_xml.text "content" raise "your hands" end rescue # Clear the buffer on an error buffer = '' end # Write the finished buffer inside the outside XmlMarkup builder outside_xml &lt;&lt; buffer end </code></pre> <p>This is a bit trickier, since it's using two separate XML builders. There's essentially no way to roll back a tag in XmlMarkup. Instead, we use a separate XmlMarkup instance for the inner content and manually give it to the outer builder -- because we're using a target for the inner builder, we can adjust the contents of the target from <em>outside</em> the XmlBuilder before we pass it on.</p> <p>So, if you run this new example with the exception, you'll get: <code>&lt;outer&gt;&lt;/outer&gt;</code> And if you run it with the exception commented out, you'll get: <code>&lt;outer&gt;&lt;inner&gt;&lt;text&gt;content&lt;/text&gt;&lt;/inner&gt;&lt;/outer&gt;</code></p> <p>Is this what you're looking for?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload