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.
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:
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\"]")
This is a bit slow but works and was easy to find and get to work.
Maybe there are just too many XML packages available in Perl and that makes it hard to find the right one.
Anyway I would love to find a solution to this problem with a perl package.
Thanks in advance.
A picture is worth a thousand words, but takes 200K.
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.
| & || & |
| < || < |
| > || > |
| [ || [ |
| ] || ] ||