Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to output special characters like angle brackets into an HTML/XHTML/XML file?

I want to put the following content into the file: <ScriptFile Make="3">
It fails for the reason of the string containing the angle brackets < and > and the double quote character ".

I have tried escaping the characters following way: ^<ScriptFile Make=""3""^>
It worked, but the output in the file was exactly the same as the escaped string.

The code snippet:

@echo off

set TEMP="^<ScriptFile Make=""3""^>"
echo %TEMP% > gen.xml
pause

How can I output the string value of TEMP variable into file gen.xml without loosing the double quotes and the angle brackets?

like image 395
Lucas Avatar asked Nov 20 '25 01:11

Lucas


1 Answers

You can extract the angle brackets out of the variable, like this:

@echo off
set TEMP1=ScriptFile Make="3"
echo ^<%TEMP1%^> > gen.xml
pause

This way, the brackets can be escaped properly, you do not need any special escaping for the string put in the variable and the gen.xml looks like expected:

D:\temp>type gen.xml
<ScriptFile Make="3">
like image 177
keenthinker Avatar answered Nov 21 '25 13:11

keenthinker