Reputation: 970
i'm trying to create a string which i want to have exaclty this form:
<atom:link rel="name" type="html" href="http://www/data/name/1"/>
I'm trying this:
String astring = "<atom:link rel="+"name"+" "+"type="+"html"+" "+"href="+"http://www/data/name/"+id+"/>"
And i take this:
<atom:link rel=name type=html href=http://www/data/name/1/>
Any ideas about this?
Upvotes: 1
Views: 114
Reputation: 40076
What is exactly your problem? missing double quote? or escaped < > ?
For missing double quote, it is just because you haven't put any double quote in the string. Please do something like "rel=\"name\""
For the latter one, I bet you have put the string as text node and have a XML writer write out the data? Because in XML, < >
has to be escaped for proper presentation of a string. You should not expect to create XML structure by giving a plain string within certain xml node . Use your XML APIs to properly construct this piece of XML structure.
Upvotes: 0
Reputation: 38635
No offense, but it seems like you haven't google much or tried to understand the root problem, which is escaping. Since this is a foudamental concept for data formats and programming, here is the page about escape characters in wikipedia.
You should then investigate for yoursefl the notion of escaping in the context of (1) java string, and (2) xml.
Upvotes: 0
Reputation: 236150
Try this:
String astring = "<atom:link rel="+"\"name\""+" "+"type="+"\"html\""+" "+"href="+"\"http://www/data/name/"+id+"\"/>"
You need to escape the "
character in the strings, do it by preceding it with a backslash: \"
Upvotes: 1
Reputation: 692231
double quotes must be escaped with a backslash inside a String literal:
String astring = "<atom:link rel=\"name\" type=\"html\" href=\"http://www/data/name/1\"/>";
Upvotes: 6