Reputation:
I have the following code:
String xmlHeader = "<?xml version="1.0" encoding="UTF-8"?>";
I can't save this token as a string value, how can I solve this problem?
Upvotes: 1
Views: 201
Reputation:
You need to escape double quotes by backslashes:
String xmlHeader = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>";
Upvotes: 2
Reputation: 532
also you can write like this:
String xmlHeader = "<?xml version='1.0' encoding='UTF-8'?>";
Upvotes: 0
Reputation: 35577
String str1="<?xml version='1.0"encoding='UTF-8"?>"
use
String str1 = "<?xml version=\'1.0\"encoding=\'UTF-8\"?>";
For your case use
String str2 = "<?xml version=\"1.0\"encoding=\"UTF-8\"?>";
Upvotes: 0
Reputation: 6479
If you want to put quotes within quotes you must use the escape sequence, \", on the interior quotes. In your example, to save this Token as a String value
String xmlHeader = "<?xml version="1.0" encoding="UTF-8"?>";
you would write
String xmlHeader = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>";
Upvotes: 1
Reputation: 234795
For this particular case the quotation characters need to be escaped by prefixing with \
:
String xmlHeader = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>";
But note that in XML, you need to use "
to escape the quotation character in an attribute value:
When do I need to use the " in xml?
Upvotes: 3
Reputation: 53839
You need to escape the "
with \
:
String xmlHeader = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>";
Upvotes: 7