-1

I want to add "<?xml-stylesheet href="view.xsl" type="text/xsl"?>" this line in below xml file after the "<?xml version="1.0" encoding="UTF-8"?>". Kindly check and provide the correct batch program.

XML File

<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet href="view.xsl" type="text/xsl"?>
<!--s1.dtd v4.20-->
<!DOCTYPE article_set SYSTEM "s1.dtd">
  • What have you written so far ? Show us your research and effort attempted please. – Kraang Prime Dec 30 '16 at 07:32
  • 2
    I'm voting to close this question as off-topic because It's a gimme-tha-codez question – Magoo Dec 30 '16 at 07:33
  • did you search in stackoverflow before posting this question ? this posts may help http://stackoverflow.com/questions/60034/how-can-you-find-and-replace-text-in-a-file-using-the-windows-command-line-envir – Kamaraj Dec 30 '16 at 07:46
  • So you basically want to insert a line of text after the first line in the file, right? – aschipfl Dec 30 '16 at 09:25
  • yes sir. i want to insert a line of text after the first line in the file. – Karthick Raja Dec 30 '16 at 09:35

1 Answers1

1

Before I start, let me recommend you to use another language that is capable of treating XML data as XML data natively; treating them as "normal" text data may damage the XML data structure.

Anyway, to insert a line of text into a file after the first line, you could use the following code:

setlocal EnableDelayedExpansion
set "SECOND=<?xml-stylesheet href="view.xsl" type="text/xsl"?>"
< "datafile.xml" > "datafile.xml.tmp" (
    set /P FIRST=""
    echo(!FIRST!
    echo(!SECOND!
    findstr "^"
)
> nul move /Y "datafile.xml.tmp" "datafile.xml"
endlocal

Limitations: the text data must be ANSI-encoded; the first line must not be longer than 1023 bytes (including the trailing line-break); the remaining lines must not be longer than 8192 bytes (also including the trailing line-break); the script does not check the content of the file, it simply inserts a line after the first one.

Next time when asking a question, please show some own efforts to solve the problem...

aschipfl
  • 33,626
  • 12
  • 54
  • 99