I'm working with a server.xml file...
Case 1:
<?xml version="1.0" encoding="UTF-8"?>
<Resource name="${app.name}" />
In catalina.properties i have declared the app.name
app.name=or
Case 2:
<?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.
Case 1
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:Downstream processing likely doesn't know how to deal with
or, and you have your "not working" case.Case 2
In case 2,
orexists in the XML file prior to parsing. After parsing, effectively, the program calling the XML parser sees the entities expanded:and is able to "work" because it knows what to do when
@nameis"or".Note that had
catalina.propertiesbeen an XML file, the expansion would have occurred then that file was parsed, and you'd be back to your "working" case.Solution
Options include one of the following:
server.xmlrather than incatalina.properties.server.xml.catalina.propertiesfile.