1

I have task scheduler xml file that i am trying to edit.

        <?xml version="1.0" encoding="UTF-16"?>
    <Task xmlns="http://schemas.microsoft.com/windows/2004/02/mit/task" version="1.4">
      <RegistrationInfo>
        <Date>2017-03-12T16:40:52.4111579</Date>
        <Author>Kevin</Author>
        <Description>Runs Batch File For Counter</Description>
        <URI>THETASKTITLEGOESHERE</URI>
      </RegistrationInfo>
  <Actions Context="Author">
    <Exec>
      <Command>"ACTIONGOESHERE"</Command>
    </Exec>
  </Actions>
</Task>

Here is what i have in the batch file.

@echo off
pushd %~dp0

xml ed -inplace -r "/Task/RegistrationInfo/Author" -v CGL XMLTEST1.xml
xml ed -inplace -r "/Task/RegistrationInfo/URI" -v CGL-FakeTitle XMLTEST1.xml
xml ed -inplace -r "/Task/Actions/Exec/Command" -v "C:\Batch\Counter.bat" XMLTEST1.xml
pause

I have tried the suggestions here; xmlstarlet update value nothing happens

Adding the " > XMLTEST1output.xml" at the end resulted in an empty file. Any suggestions would be helpful. Thank you!

Cyrus
  • 84,225
  • 14
  • 89
  • 153
  • What does option `-inplace` do? – Cyrus Dec 18 '17 at 14:07
  • some `xmlstartlet`s have an `--inplace` option which saves the changes to the original file. But that doesn't explain why (for instance) the `.../URI` value doesn't change to CGL-FakeTitle in my tests. None of these work with `-r` or `-u` ? Anyone spot the error in "our" thinking? Thanks and Good luck to all. – shellter Dec 18 '17 at 18:15
  • And see my comment on the link above. Don't use `xml ... file.xml > file.xml`! – shellter Dec 18 '17 at 18:20
  • I tried both ways but could not get it to work. I'd rather not use --inplace and have it as a template with an output.xml that I can change the name on afterwards. – KevinColby650 Dec 20 '17 at 15:18

1 Answers1

1

This works for me with Linux and xmlstarlet:

xmlstarlet edit --inplace \
           -N x="http://schemas.microsoft.com/windows/2004/02/mit/task" \
           -u "//x:Task/x:RegistrationInfo/x:Author" -v "CGL" \
           -u "//x:Task/x:RegistrationInfo/x:URI"    -v "CGL-FakeTitle" \
           -u "//x:Task/x:Actions/x:Exec/x:Command"  -v "C:\Batch\Counter.bat" XMLTEST1.xml

I switched from -r (rename) to -u to update values. In XMLTEST1.xml I replaced UTF-16 with UTF-8.

Cyrus
  • 84,225
  • 14
  • 89
  • 153