Replacing Text within XML

  • Wayne

    Wayne - 2011-10-02

    I am having a pretty big issue.  I cannnot get sfk to replace text on a XML file. It constantly returns that 0 changes have been made.  I have been able to save a portion of the XML as a text file and then I can get it to replace sometimes.  Other times it states it doesn't find anything.  I need some help.

    I am attempting to replace text within an XML document that has been exported from the task scheduler within Windows 7.  I export the XML file and open it in notepad.  I then replace the Date data with the word datetime, the Author data with the word username, StartBoundary time data with the word datetime, userid data with the words computername/username, and the command data with the word progpathname.

    The command I am using to change the items back is:
    sfk replace "test.xml" -text -quiet _username_"%username%"_ _datetime_%datetimex%_ _computername_"%computername%"_ _progpathname_"C:\Program Files\test\test.exe"_ -yes

    Here is what I changed in the XML file below.

    Here is the XML File with the changes.
    <?xml version="1.0" encoding="UTF-16"?>
    <Task version="1.2" xmlns="">
        <Principal id="Author">
      <Actions Context="Author">

  • stahlworks

    stahlworks - 2011-10-03

    The string


    says this file is not a plain ASCII text file, but a wide character file using two bytes per character.
    Please try "sfk hexdump filename", then you will see something like

     >FFFE7400 68006900 73000900 69007300< ..t.h.i.s...i.s. 00000000
     >09006100 09007400 61006200 62006500< ..a...t.a.b.b.e. 00000010
     >64000900 74006500 78007400 0D000A00< d...t.e.x.t..... 00000020

    So if every 2nd byte is "00" this means it is using 2 bytes per character.
    SFK cannot handle this format, and treats it as a binary file.
    Replacing text within such a binary file is complicated.
    For example, to replace the word "this" by "that", you have to use

    -bin /7400680069007300/7400680061007400/

    which replaces a binary byte block of 2-byte characters by another block of 2-byte characters
    (every ASCII character written as a hex code, and followed by "00"). you may also try
    the command "sfk chars myword" to have all hex codes for a string "myword" listed.
    But because you don't want to replace fixed strings, but strings taken from batch parameters
    or environment variables, it would become much more complicated or rather impossible
    to find a workaround. So I'd suggest to google for a different tool.


Log in to post a comment.