How to append to certain line of file?

后端 未结 2 1445
闹比i
闹比i 2020-12-12 07:25

I want to append to a file but I want to start appending before tag end. appears. How can I do that?

var fs = require(\"fs\");
fs.a         


        
2条回答
  •  时光取名叫无心
    2020-12-12 07:52

    A good approach is to split the file into a wrapper file and a body file. The wrapper just contains the outermost tag and an entity reference to the body file. Your program can then append to the end of the body file, whereas anyone reading the file as XML should read the wrapper file. The wrapper file will look something like this:

    
    ]>
    &e;
    

    Using "xml" as an element name, by the way, is bad practice. All names starting "xml" are reserved for future use by W3C.

    This approach may not work if you're reading the XML in a browser. I think that some browsers' XML parsers don't support external entities.

提交回复
热议问题