<?xml version="1.0" encoding="windows-1252"?>
<node id="816445" title="XPATH problems" created="2010-01-08 22:40:15" updated="2010-01-08 22:40:15">
<type id="115">
perlquestion</type>
<author id="424604">
gam3</author>
<data>
<field name="doctext">
I have spent a few hours trying to write a program in perl that will find a node in one file using XPath and then find a node in a second file using an XPath.  Then replace the first node with the second and write out the modified file.
&lt;p&gt;
I did not see how to replace the node with XML::XPath and I could not get XML::Twig to find my paths.  I gave up at one point and wrote it in ruby:
&lt;p&gt;
&lt;code&gt;
#!/usr/bin/ruby -w

require 'rexml/document'
include REXML

xmlfile1 = File.new("wiki.html")
xmldoc1 = Document.new(xmlfile1)

xmlfile2 = File.new("timeline.html")
xmldoc2 = Document.new(xmlfile2)

node1 = XPath.first(xmldoc1, "//div[@id=\"metanav\"]")
node2 = XPath.first(xmldoc2, "//div[@id=\"metanav\"]")

node1.replace_with(node2)

print xmldoc1.to_s;
&lt;/code&gt;

This is a bit slow but works and was easy to find and get to work.
&lt;p&gt;
Maybe there are just too many XML packages available in Perl and that makes it hard to find the right one.
&lt;p&gt;
Anyway I would love to find a solution to this problem with a perl package.
&lt;p&gt;
Thanks in advance.
&lt;p&gt;
&lt;!-- Node text goes above. Div tags should contain sig only --&gt;
&lt;div class="pmsig"&gt;&lt;div class="pmsig-424604"&gt;
-- gam3&lt;br/&gt;
&lt;small&gt;A picture is worth a thousand words, but takes 200K.&lt;/small&gt;
&lt;/div&gt;&lt;/div&gt;
</field>
</data>
</node>
