使用批处理脚本在XML的特定行插入字符串 [英] Use batch script to insert a string at a particular line in XML

查看:274
本文介绍了使用批处理脚本在XML的特定行插入字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是编程新手. 有人可以教我如何使用批处理脚本在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

我想在第2行上添加一个格式字符串,因此它具有:

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.

干杯, 艾伦

推荐答案

@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

这篇关于使用批处理脚本在XML的特定行插入字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆