tags:

views:

53

answers:

0

I have managed to figure out the primary part of my question, "how do I insert one XML document into another?" The result I get will work but the printed XML is missing a linefeed.

s = <<EOF
<application>
  <email>
    <host>mail.test.com</host>
    <port>25</port>
  </email>
</application>
EOF

p = <<EOF
<auth>
  <user>godber</user>
  <pass>foo</pass>
</auth>
EOF

subdoc = REXML::Document.new(p)
doc = REXML::Document.new(s)
doc.root.insert_after( '//email', subdoc.root )
doc.write

this outputs the following, which you can see has the auth tag starting immediately after the email close tag without a newline

<application>
  <email>
    <host>mail.test.com</host>
    <port>25</port>
  </email><auth>
  <user>godber</user>
  <pass>foo</pass>
</auth>
</application>

Actually, just as I have finished this I realized that I can change my last line to

doc.write( $stdout, 2 )

This was clearly written in the rexml tutorial, I had just overlooked it assuming that something else was wrong. I guess I will submit this just in case anyone else is puzzled by this. If anyone has tips along these lines, I'd be happy to hear them.