Given:
public static final String XML_POLICY =
"<?xml version="1.0"?>"
+"<!DOCTYPE cross-domain-policy SYSTEM "/xml/dtds/cross-domain-policy.dtd">"
+ "<cross-domain-policy>"
+ "<allow-access-from domain="*" to-ports="*" />"
+ "</cross-domain-policy>";
I am getting compile errors on the
"<?xml version="1.0"?>"
it says ‘;‘ expected.
and on
+"<!DOCTYPE cross-domain-policy SYSTEM "/xml/dtds/cross-domain-policy.dtd">"
it says “cannot find symbol, symbol: class xml and class dtds”
What could be the possible cause? IDE is Netbeans 6.8 Beta.
You need to escape the double quotes – and it’s not just the first line, either. The doctype and allow-access-from lines require it too.
An alternative it to use single quotes within the XML, which is fine in most places, and makes the code simpler to read:
Note that there’s nothing Netbeans or XML-specific about this. A double quote is used to indicate the start and end of a string, which is why you need to escape it if you want one in the middle. For example:
There are various other escape sequences in Java – see section 3.10.6 of the language specification for more details.