Hello Monks,
This is my first foray into using xml and perl together. I found a thread about swapping xml elements, but unlike that thread, I want to swap them out from an external file. Here is what I have so far: first, an xml file with "head" elements that I want to tag up. So, I run this:
#!/usr/bin/perl -w
use XML::Twig;
my $file = $ARGV[0];
my $twig= new XML::Twig(TwigRoots => {head => 1});
$twig->parsefile($file);
$twig->print;
which scrapes out all and only the head elements. Then I write it all to a file from the command line. That file looks something like this:
<TEI>
<head>Note VII</head>
<head>Title Page </head>
<head>Copyright Page </head>
<head>Preface </head>
...
</TEI>
Next, I retag the head elements in a text editor. Specifically, I find all roman numerals, and tag them with an xml element. I know I could do this in the script, but in this case, I want to do it by hand for oversight. So, I end up with a list of head elements, tagged as I want them, looking something like this:
<TEI>
<head>Note <romanNumeral>VII</romanNumeral></head>
<head>Title Page </head>
<head>Copyright Page </head>
<head>Preface </head>
...
</TEI>
Now, I want to go back through the file I extracted the head elements from, and replace the head tags there with the head tags I've extracted and tagged up in the external file. How would I do that?
Thanks in advance for your help!
-
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.