Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

comment on

( [id://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":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others avoiding work at the Monastery: (6)
As of 2024-04-16 11:15 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found