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:
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'.
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
-L
or--inplace
option 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/>.
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).
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'.