Q:

Use batch script to insert a string at a particular line in XML

i am new to programming.
Can some1 kindly teach me how to insert a new line in an XML file using batch script?
Current file has first 2 lines:
<?xml version="1.0"?>
<Workbook xmlns="urn:schemas-microsoft-com:xxxxxxxxx

I want to add a format string on Line 2 so it has:
<?xml version="1.0"?>
<?mso-application progid="Excel.Sheet"?>
<Workbook xmlns="urn:schemas-microsoft-com:xxxxxxxxxx

It has to be using batch-file as the rest of the file is built with it.
Cheers,
Alan

A:

@echo off
    setlocal enableextensions disabledelayedexpansion
    set "secondLine=^<?mso-application progid="Excel.Sheet"?^>"
    (for /f "delims=" %%a in (input.xml) do (
        echo(%%a
        if defined secondLine ( 
            echo(%secondLine%
            set "secondLine="
        )
    )) > output.xml

