I need to copy, for multiple lines, the contents of <sourcetag>Text</sourcetag> to <tagtoupdate></tagtoupdate> (empty)..
I assumed the edit-update function was the correct one. It seems to be doing something, but the result is the same as when I started. Is the "/Object/SourceTag" allowed as parameter? Most examples have a hardcoded text.
xml ed -u "/Object/TagToUpdate" -v "/Object/SourceTag" MyXMLFile.xml
If not allowed, what would be the solution?
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I need to copy, for multiple lines, the contents of <sourcetag>Text</sourcetag> to <tagtoupdate></tagtoupdate> (empty)..
I assumed the edit-update function was the correct one. It seems to be doing something, but the result is the same as when I started. Is the "/Object/SourceTag" allowed as parameter? Most examples have a hardcoded text.
xml ed -u "/Object/TagToUpdate" -v "/Object/SourceTag" MyXMLFile.xml
If not allowed, what would be the solution?
"-v" is used to specify a string, "-x" is for an XPath expression, so
something along the lines of
xml ed -u "/Object/TagToUpdate" -x "/Object/SourceTag/text()" MyXMLFile.xml
Also, note the -L or --inplace option if you want to edit the original file.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Thanks Postavsky, but it didn't really work. Like other things I tried yesterday, it replaces my <tagtoupdate></tagtoupdate> into <tagtoupdate></tagtoupdate>.
By the way, as I'm a bit of a noob here, I export the result to another file.
Last edit: teqie1979 2017-08-11
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Update: it seems not to collect the <sourcetag> contents. Also, If I fill in something in the <tagtoupdate>, it leaves it alone (value stays).</tagtoupdate></sourcetag>
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
In the end I used SED to manipulate the data. I would have liked this better, as it is a lot better to understand. I gave it another try, but it still won't work. I have the same version, but compiled for Windows. Maybe I can find a Linux box somewhere to test if it behaves differently.
I know <tag></tag> and <tag> are both empty tags. I reported it more as a proof that it was updating the file, but it put in 'nothing'.</tag>
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I need to copy, for multiple lines, the contents of <sourcetag>Text</sourcetag> to <tagtoupdate></tagtoupdate> (empty)..
I assumed the edit-update function was the correct one. It seems to be doing something, but the result is the same as when I started. Is the "/Object/SourceTag" allowed as parameter? Most examples have a hardcoded text.
xml ed -u "/Object/TagToUpdate" -v "/Object/SourceTag" MyXMLFile.xml
If not allowed, what would be the solution?
On Thu, Aug 10, 2017 at 3:53 PM, Arvid Egbertzen teqie1979@users.sf.net wrote:
"-v" is used to specify a string, "-x" is for an XPath expression, so
something along the lines of
Also, note the
-Lor--inplaceoption if you want to edit the original file.Thanks Postavsky, but it didn't really work. Like other things I tried yesterday, it replaces my <tagtoupdate></tagtoupdate> into <tagtoupdate></tagtoupdate>.
By the way, as I'm a bit of a noob here, I export the result to another file.
Last edit: teqie1979 2017-08-11
Update: it seems not to collect the <sourcetag> contents. Also, If I fill in something in the <tagtoupdate>, it leaves it alone (value stays).</tagtoupdate></sourcetag>
Works for me, maybe you typo'd a tag name? Note that
<Tag/>and<Tag></Tag>are 100% identical as far as xmlstarlet is concerned.Thanks again Noam for your reply.
In the end I used SED to manipulate the data. I would have liked this better, as it is a lot better to understand. I gave it another try, but it still won't work. I have the same version, but compiled for Windows. Maybe I can find a Linux box somewhere to test if it behaves differently.
I know <tag></tag> and <tag> are both empty tags. I reported it more as a proof that it was updating the file, but it put in 'nothing'.</tag>