KevinColby650
KevinColby650

Reputation: 11

xmlstarlet update through batch file not updating/working

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!

Upvotes: 1

Views: 289

Answers (1)

Cyrus
Cyrus

Reputation: 88879

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.

Upvotes: 1

Related Questions