Beefy Boxes and Bandwidth Generously Provided by pair Networks RobOMonk
go ahead... be a heretic
 
PerlMonks  

Comment on

( #3333=superdoc: print w/ replies, xml ) Need Help??
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:

#!/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;
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.

-- gam3
A picture is worth a thousand words, but takes 200K.

In reply to XPATH problems by gam3

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • 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:
    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
  • Outside of code tags, you may need to use entities for some characters:
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?
    Username:
    Password:

    What's my password?
    Create A New User
    Chatterbox?
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others rifling through the Monastery: (8)
    As of 2014-04-21 15:26 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      April first is:







      Results (495 votes), past polls