Edit XML with batch file

前端 未结 5 936
别那么骄傲
别那么骄傲 2021-01-06 06:41

I am wondering if there is any way to create a batch file that can edit a line in an XML document. The line would be identified by the preceding line. the idea would be as

5条回答
  •  抹茶落季
    2021-01-06 07:19

    XML isn't line-based, so an assumption that you can look for something in the file by checking it on a line-by-line basis, is either prone to problems, or relies on other assumptions besides XML. (if you are getting your file from a certain type of software, how do you know it is always going to produce output lines in that particular way?)

    Having said that, I'd take a look at JSDB Javascript, which has E4X built-in. E4X makes it particularly simple to manipulate XML, as long as you can read it all into memory; it's not a stream-based system. Though you could use JSDB without E4X and handle file I/O using streams:

    var Sin = new Stream('file://c:/tmp/testin.xml');
    var Sout = new Stream('file://c:/tmp/testout.xml','w');
    while (!Sin.eof)
    {
       var Lin = Sin.readLine();
       var Lout = some_magic_function(Lin); // do your processing here
       Sout.writeLine(Lout);
    }
    Sin.close(); Sout.close();
    

提交回复
热议问题