<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DZone Snippets: insert_before code</title>
    <link>http://snippets.dzone.com/posts</link>
    <pubDate>Sun, 18 May 2008 03:29:02 GMT</pubDate>
    <description>DZone Snippets: insert_before code</description>
    <item>
      <title>Inserting an XML node into a REXML::Document</title>
      <link>http://snippets.dzone.com/posts/show/4573</link>
      <description>// Reads an XML document, and inserts an element after the root element.&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;require 'rexml/document'&lt;br /&gt;include REXML&lt;br /&gt;&lt;br /&gt;file = File.new('journal250907.xml')&lt;br /&gt;doc = Document.new(file)&lt;br /&gt;&lt;br /&gt;puts doc&lt;br /&gt;&lt;br /&gt;o_element = Element.new('abc')&lt;br /&gt;o_element.text = "123"&lt;br /&gt;&lt;br /&gt;o_node = doc.elements['journal/entry']&lt;br /&gt;&lt;br /&gt;o_node.parent.insert_before o_node, o_element&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Wed, 26 Sep 2007 18:03:46 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/4573</guid>
      <author>jrobertson (James Robertson)</author>
    </item>
  </channel>
</rss>
