How to make XML formatted using batch script tag by tag(Pretty Print)?
up vote
0
down vote
favorite
Suppose I am having below format in one file:
`<xml><tag><othertag>ABC</othertag></tag></xml>`
But I need below formatted output :
<xml>
<tag>
<othertag>ABC</othertag>
</tag>
This formatted output i need it in other file.
help me with the batch script which will be able to do such formatting.
xml batch-file formatting
add a comment |
up vote
0
down vote
favorite
Suppose I am having below format in one file:
`<xml><tag><othertag>ABC</othertag></tag></xml>`
But I need below formatted output :
<xml>
<tag>
<othertag>ABC</othertag>
</tag>
This formatted output i need it in other file.
help me with the batch script which will be able to do such formatting.
xml batch-file formatting
this can be done easy with xslt transformation and a script using vbscript,jscript or powershell (which are installed by default on windows) called by a batch script. Later I'll try to create a script for this.
– npocmaka
Nov 10 at 18:22
Working with XML in batch can be very tricky, due to all the special characters encountered. Search for xml formatter on google and you should find plenty of free software that can convert between deflated and pretty formatted forms.
– jwdonahue
Nov 10 at 19:28
2
Possible duplicate of Using batch code to mass xml formatting?
– jwdonahue
Nov 10 at 19:32
Take the tour, read How to Ask, and Minimal, Complete, and Verifiable example.
– jwdonahue
Nov 10 at 19:34
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
Suppose I am having below format in one file:
`<xml><tag><othertag>ABC</othertag></tag></xml>`
But I need below formatted output :
<xml>
<tag>
<othertag>ABC</othertag>
</tag>
This formatted output i need it in other file.
help me with the batch script which will be able to do such formatting.
xml batch-file formatting
Suppose I am having below format in one file:
`<xml><tag><othertag>ABC</othertag></tag></xml>`
But I need below formatted output :
<xml>
<tag>
<othertag>ABC</othertag>
</tag>
This formatted output i need it in other file.
help me with the batch script which will be able to do such formatting.
xml batch-file formatting
xml batch-file formatting
edited Nov 11 at 13:58
LotPings
15.6k61531
15.6k61531
asked Nov 10 at 17:26
umesh yadav
91
91
this can be done easy with xslt transformation and a script using vbscript,jscript or powershell (which are installed by default on windows) called by a batch script. Later I'll try to create a script for this.
– npocmaka
Nov 10 at 18:22
Working with XML in batch can be very tricky, due to all the special characters encountered. Search for xml formatter on google and you should find plenty of free software that can convert between deflated and pretty formatted forms.
– jwdonahue
Nov 10 at 19:28
2
Possible duplicate of Using batch code to mass xml formatting?
– jwdonahue
Nov 10 at 19:32
Take the tour, read How to Ask, and Minimal, Complete, and Verifiable example.
– jwdonahue
Nov 10 at 19:34
add a comment |
this can be done easy with xslt transformation and a script using vbscript,jscript or powershell (which are installed by default on windows) called by a batch script. Later I'll try to create a script for this.
– npocmaka
Nov 10 at 18:22
Working with XML in batch can be very tricky, due to all the special characters encountered. Search for xml formatter on google and you should find plenty of free software that can convert between deflated and pretty formatted forms.
– jwdonahue
Nov 10 at 19:28
2
Possible duplicate of Using batch code to mass xml formatting?
– jwdonahue
Nov 10 at 19:32
Take the tour, read How to Ask, and Minimal, Complete, and Verifiable example.
– jwdonahue
Nov 10 at 19:34
this can be done easy with xslt transformation and a script using vbscript,jscript or powershell (which are installed by default on windows) called by a batch script. Later I'll try to create a script for this.
– npocmaka
Nov 10 at 18:22
this can be done easy with xslt transformation and a script using vbscript,jscript or powershell (which are installed by default on windows) called by a batch script. Later I'll try to create a script for this.
– npocmaka
Nov 10 at 18:22
Working with XML in batch can be very tricky, due to all the special characters encountered. Search for xml formatter on google and you should find plenty of free software that can convert between deflated and pretty formatted forms.
– jwdonahue
Nov 10 at 19:28
Working with XML in batch can be very tricky, due to all the special characters encountered. Search for xml formatter on google and you should find plenty of free software that can convert between deflated and pretty formatted forms.
– jwdonahue
Nov 10 at 19:28
2
2
Possible duplicate of Using batch code to mass xml formatting?
– jwdonahue
Nov 10 at 19:32
Possible duplicate of Using batch code to mass xml formatting?
– jwdonahue
Nov 10 at 19:32
Take the tour, read How to Ask, and Minimal, Complete, and Verifiable example.
– jwdonahue
Nov 10 at 19:34
Take the tour, read How to Ask, and Minimal, Complete, and Verifiable example.
– jwdonahue
Nov 10 at 19:34
add a comment |
2 Answers
2
active
oldest
votes
up vote
0
down vote
try this (it does not check if the xml has valid syntax):
call ::beautifyXml "c:some.xml"
call ::beautifyXml "c:some.xml" > "c:new.xml"
exit /b %errorlevel%
:beautifyXml
powershell "function fx($xml, $i=2){$SW=New-Object System.IO.StringWriter;$XW=New-Object System.XMl.XmlTextWriter $SW; $XW.Formatting='indented';$XW.Indentation=$i;([xml]$xml).WriteContentTo($XW);$XW.Flush();$SW.Flush();Write-Output $SW.ToString();};FX (gc -path """%~f1""") -i 4"
goto :eof
if you the new file looks ok you can add additional move command to replace the old one.
1
With XML files mostly encoded in UTF8 I'd prefer to write to file in the powershell part probaply with an -Encoding parameter.
– LotPings
Nov 11 at 13:57
@LotPings - Good point. Later (if I have the time) I'll try to edit the script.
– npocmaka
Nov 11 at 14:06
add a comment |
up vote
0
down vote
A XML file should not be processed via a Batch file. However, this particular example give me the opportunity to get some fun with a Batch file, and it works! ;)
@echo off
setlocal EnableDelayedExpansion
for /F "tokens=2 delims=`" %%a in (input.txt) do set "format=%%a"
for /F %%a in ('copy /Z "%~F0" NUL') do set NL=%%a^
% Don't remove %
% these lines %
set "SP= "
set "format=%format:></=>^!NL^!^!SP:~0,-8^!" ^& set "SP=^!SP:~0,-4^!" ^& set /P "=</%"
< NUL (set /P "=%format:><=>!NL!!SP!" & set "SP= !SP!" & set /P "=<%" & echo/) > output.txt
Output:
<xml>
<tag>
<othertag>ABC</othertag>
</tag>
</xml>
For a description on the method used, see this thread.
add a comment |
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
0
down vote
try this (it does not check if the xml has valid syntax):
call ::beautifyXml "c:some.xml"
call ::beautifyXml "c:some.xml" > "c:new.xml"
exit /b %errorlevel%
:beautifyXml
powershell "function fx($xml, $i=2){$SW=New-Object System.IO.StringWriter;$XW=New-Object System.XMl.XmlTextWriter $SW; $XW.Formatting='indented';$XW.Indentation=$i;([xml]$xml).WriteContentTo($XW);$XW.Flush();$SW.Flush();Write-Output $SW.ToString();};FX (gc -path """%~f1""") -i 4"
goto :eof
if you the new file looks ok you can add additional move command to replace the old one.
1
With XML files mostly encoded in UTF8 I'd prefer to write to file in the powershell part probaply with an -Encoding parameter.
– LotPings
Nov 11 at 13:57
@LotPings - Good point. Later (if I have the time) I'll try to edit the script.
– npocmaka
Nov 11 at 14:06
add a comment |
up vote
0
down vote
try this (it does not check if the xml has valid syntax):
call ::beautifyXml "c:some.xml"
call ::beautifyXml "c:some.xml" > "c:new.xml"
exit /b %errorlevel%
:beautifyXml
powershell "function fx($xml, $i=2){$SW=New-Object System.IO.StringWriter;$XW=New-Object System.XMl.XmlTextWriter $SW; $XW.Formatting='indented';$XW.Indentation=$i;([xml]$xml).WriteContentTo($XW);$XW.Flush();$SW.Flush();Write-Output $SW.ToString();};FX (gc -path """%~f1""") -i 4"
goto :eof
if you the new file looks ok you can add additional move command to replace the old one.
1
With XML files mostly encoded in UTF8 I'd prefer to write to file in the powershell part probaply with an -Encoding parameter.
– LotPings
Nov 11 at 13:57
@LotPings - Good point. Later (if I have the time) I'll try to edit the script.
– npocmaka
Nov 11 at 14:06
add a comment |
up vote
0
down vote
up vote
0
down vote
try this (it does not check if the xml has valid syntax):
call ::beautifyXml "c:some.xml"
call ::beautifyXml "c:some.xml" > "c:new.xml"
exit /b %errorlevel%
:beautifyXml
powershell "function fx($xml, $i=2){$SW=New-Object System.IO.StringWriter;$XW=New-Object System.XMl.XmlTextWriter $SW; $XW.Formatting='indented';$XW.Indentation=$i;([xml]$xml).WriteContentTo($XW);$XW.Flush();$SW.Flush();Write-Output $SW.ToString();};FX (gc -path """%~f1""") -i 4"
goto :eof
if you the new file looks ok you can add additional move command to replace the old one.
try this (it does not check if the xml has valid syntax):
call ::beautifyXml "c:some.xml"
call ::beautifyXml "c:some.xml" > "c:new.xml"
exit /b %errorlevel%
:beautifyXml
powershell "function fx($xml, $i=2){$SW=New-Object System.IO.StringWriter;$XW=New-Object System.XMl.XmlTextWriter $SW; $XW.Formatting='indented';$XW.Indentation=$i;([xml]$xml).WriteContentTo($XW);$XW.Flush();$SW.Flush();Write-Output $SW.ToString();};FX (gc -path """%~f1""") -i 4"
goto :eof
if you the new file looks ok you can add additional move command to replace the old one.
edited Nov 10 at 21:33
answered Nov 10 at 21:20
npocmaka
41k1083125
41k1083125
1
With XML files mostly encoded in UTF8 I'd prefer to write to file in the powershell part probaply with an -Encoding parameter.
– LotPings
Nov 11 at 13:57
@LotPings - Good point. Later (if I have the time) I'll try to edit the script.
– npocmaka
Nov 11 at 14:06
add a comment |
1
With XML files mostly encoded in UTF8 I'd prefer to write to file in the powershell part probaply with an -Encoding parameter.
– LotPings
Nov 11 at 13:57
@LotPings - Good point. Later (if I have the time) I'll try to edit the script.
– npocmaka
Nov 11 at 14:06
1
1
With XML files mostly encoded in UTF8 I'd prefer to write to file in the powershell part probaply with an -Encoding parameter.
– LotPings
Nov 11 at 13:57
With XML files mostly encoded in UTF8 I'd prefer to write to file in the powershell part probaply with an -Encoding parameter.
– LotPings
Nov 11 at 13:57
@LotPings - Good point. Later (if I have the time) I'll try to edit the script.
– npocmaka
Nov 11 at 14:06
@LotPings - Good point. Later (if I have the time) I'll try to edit the script.
– npocmaka
Nov 11 at 14:06
add a comment |
up vote
0
down vote
A XML file should not be processed via a Batch file. However, this particular example give me the opportunity to get some fun with a Batch file, and it works! ;)
@echo off
setlocal EnableDelayedExpansion
for /F "tokens=2 delims=`" %%a in (input.txt) do set "format=%%a"
for /F %%a in ('copy /Z "%~F0" NUL') do set NL=%%a^
% Don't remove %
% these lines %
set "SP= "
set "format=%format:></=>^!NL^!^!SP:~0,-8^!" ^& set "SP=^!SP:~0,-4^!" ^& set /P "=</%"
< NUL (set /P "=%format:><=>!NL!!SP!" & set "SP= !SP!" & set /P "=<%" & echo/) > output.txt
Output:
<xml>
<tag>
<othertag>ABC</othertag>
</tag>
</xml>
For a description on the method used, see this thread.
add a comment |
up vote
0
down vote
A XML file should not be processed via a Batch file. However, this particular example give me the opportunity to get some fun with a Batch file, and it works! ;)
@echo off
setlocal EnableDelayedExpansion
for /F "tokens=2 delims=`" %%a in (input.txt) do set "format=%%a"
for /F %%a in ('copy /Z "%~F0" NUL') do set NL=%%a^
% Don't remove %
% these lines %
set "SP= "
set "format=%format:></=>^!NL^!^!SP:~0,-8^!" ^& set "SP=^!SP:~0,-4^!" ^& set /P "=</%"
< NUL (set /P "=%format:><=>!NL!!SP!" & set "SP= !SP!" & set /P "=<%" & echo/) > output.txt
Output:
<xml>
<tag>
<othertag>ABC</othertag>
</tag>
</xml>
For a description on the method used, see this thread.
add a comment |
up vote
0
down vote
up vote
0
down vote
A XML file should not be processed via a Batch file. However, this particular example give me the opportunity to get some fun with a Batch file, and it works! ;)
@echo off
setlocal EnableDelayedExpansion
for /F "tokens=2 delims=`" %%a in (input.txt) do set "format=%%a"
for /F %%a in ('copy /Z "%~F0" NUL') do set NL=%%a^
% Don't remove %
% these lines %
set "SP= "
set "format=%format:></=>^!NL^!^!SP:~0,-8^!" ^& set "SP=^!SP:~0,-4^!" ^& set /P "=</%"
< NUL (set /P "=%format:><=>!NL!!SP!" & set "SP= !SP!" & set /P "=<%" & echo/) > output.txt
Output:
<xml>
<tag>
<othertag>ABC</othertag>
</tag>
</xml>
For a description on the method used, see this thread.
A XML file should not be processed via a Batch file. However, this particular example give me the opportunity to get some fun with a Batch file, and it works! ;)
@echo off
setlocal EnableDelayedExpansion
for /F "tokens=2 delims=`" %%a in (input.txt) do set "format=%%a"
for /F %%a in ('copy /Z "%~F0" NUL') do set NL=%%a^
% Don't remove %
% these lines %
set "SP= "
set "format=%format:></=>^!NL^!^!SP:~0,-8^!" ^& set "SP=^!SP:~0,-4^!" ^& set /P "=</%"
< NUL (set /P "=%format:><=>!NL!!SP!" & set "SP= !SP!" & set /P "=<%" & echo/) > output.txt
Output:
<xml>
<tag>
<othertag>ABC</othertag>
</tag>
</xml>
For a description on the method used, see this thread.
answered Nov 11 at 17:22
Aacini
50.4k75173
50.4k75173
add a comment |
add a comment |
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53241546%2fhow-to-make-xml-formatted-using-batch-script-tag-by-tagpretty-print%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
this can be done easy with xslt transformation and a script using vbscript,jscript or powershell (which are installed by default on windows) called by a batch script. Later I'll try to create a script for this.
– npocmaka
Nov 10 at 18:22
Working with XML in batch can be very tricky, due to all the special characters encountered. Search for xml formatter on google and you should find plenty of free software that can convert between deflated and pretty formatted forms.
– jwdonahue
Nov 10 at 19:28
2
Possible duplicate of Using batch code to mass xml formatting?
– jwdonahue
Nov 10 at 19:32
Take the tour, read How to Ask, and Minimal, Complete, and Verifiable example.
– jwdonahue
Nov 10 at 19:34