I’m using loadFromXML method of java.util.Properties class to parse an XML file that contains some application parameters. Value of one of these parameters is an HTML string as follows:
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE properties SYSTEM "http://java.sun.com/dtd/properties.dtd">
<properties>
<entry key="THREAD_COUNT">4</entry>
<entry key="SENDER_EMAIL">MAIL@SOMESITE.COM</entry>
<entry key="EMAIL_SUBJECT">SAMPLE SUBJECT</entry>
<entry key="EMAIL_BODY"><span style='font-family : Monotype Corsiva ; font-size:14pt'>SAMPLE TEXT</span></entry>
</properties>
When I have such a value, loadFromXML method throws the following exception:
java.util.InvalidPropertiesFormatException: org.xml.sax.SAXParseException: Element type "span" must be declared.
at java.util.XMLUtils.load(XMLUtils.java:59)
at java.util.Properties.loadFromXML(Properties.java:852)
at com.test.mail.ConfigReader.<init>(ConfigReader.java:27)
at com.test.mail.ConfigReader.getInstance(ConfigReader.java:43)
at com.test.mail.SendMail.readParameters(SendMail.java:64)
at com.test.mail.SendMail.startJob(SendMail.java:29)
at com.test.mail.SendMail.main(SendMail.java:24)
Is there a way to use such a value in an XML properties file?
Use a CDATA section inside your xml, to mark it as data, otherwise it will be parsed as a part of your xml:
See http://www.w3schools.com/xml/xml_cdata.asp