开发者

bad encoding for xml

I have a string like this " <person name="peter" ><\person>"

URL encoding

URLEncoder.encode(person.toString(),"UTF-8");

but the encoding is bad because for spaces make + insted of %20 and for 开发者_Python百科= he gives other values can you guys help me?


This is exactly as specified in the URLEncoder javaDoc. Space is converted to + and = is "unsafe" and thus encoded to %3D.

If you need a %20 instead of the +, just do some post processing:

URLEncoder.encode(person.toString(),"UTF-8").replace("+", "%20");


Considering your comment I assume you want to decode the webservice answer.

// the answer you receive from the webservice
string webserviceResponse = "%3Cperson+name%3D%22peter%22%3E%3C%2Fperson%3E";

// turn into a "good" Xml string
string person = URLDecoder.decode(webserviceResponse, "UTF-8");

will give you

<person name="peter"></person>

as the value of person.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜