go ahead... be a heretic | |
PerlMonks |
Re^3: Update nodes in XML documentby choroba (Cardinal) |
on Mar 27, 2018 at 07:00 UTC ( [id://1211821]=note: print w/replies, xml ) | Need Help?? |
> the XML will be loaded from STDIN. I am sorry, but I don't have strong perl skills :( Perl skills are irrelevant here. You just need to read the documentation.
> update only the alt-title with origin="tilte" Again, not a Perl skills question. findnodes uses XPath Expressions, so just modify it: Is it "tilte" or "title"? > the new values will be taken from another file which will contain the same number of lines as the nodes. Do you know how to read lines from a file? See open and the diamond operator in perlop. For example, I created an input file called 1 with the following contents:
Then, I created a simple XML file called 1.xml:
Finally, here's the script that replaces the text in two with origin="a" by the values read from the given file. $. is a special variable that contains the input's line number, you can use it to index the nodes in the XPath Expression:
Run as
In Section
Seekers of Perl Wisdom
|
|