I'm working with a server.xml file...
<?xml version="1.0" encoding="UTF-8"?>
<Resource name="${app.name}" />
In catalina.properties
i have declared the app.name
app.name=or
<?xml version="1.0" encoding="UTF-8"?>
<Resource name="or" />
The problem is why case 2 is working and case 1 not? Why in case 1 XML entities not parsing?
I.e the output is :
<Resource name= "or" /> //in case 1
<Resource name= "or" /> //in case 2
Key point: Entity expansion happens during XML parsing.
In case 1, during parsing, there are no entities in Resources/@name
– just ${app.name}
, which the program calling the XML parser would presumably go on to substitute the literal text, or
, for the variable:
<Resource name="or" />
Downstream processing likely doesn't know how to deal with or
, and you have your "not working" case.
In case 2, or
exists in the XML file prior to parsing. After parsing, effectively, the program calling the XML parser sees the entities expanded:
<Resource name="or" />
and is able to "work" because it knows what to do when @name
is "or"
.
Note that had catalina.properties
been an XML file, the expansion would have occurred then that file was parsed, and you'd be back to your "working" case.
Options include one of the following:
server.xml
rather than in catalina.properties
.server.xml
.catalina.properties
file.