Proper way to store an url in xml?

♀尐吖头ヾ 提交于 2019-12-07 17:15:10

问题


I am storing data in xml file, In one of the node I have to store an url which consists of special character like & I used &amp instead of & and xml shows no error but when I did SAX parsing String value returned within the node is the string which is after &,

I am guessing the way I am storing the url is not proper.

What is right way of storing an url in xml.

Currently I am storing as,

<param>http://www.example.com?param1=abc&amp;v=1</param>

XML has no errors, but SAX parser won't return the whole url.

EDIT: I have semicolon after &amp in the url, I missed it the first time.

Solution: It was not the problem with XML , but the way I handled XML in XMLHandler,
I was using new String(ch,start,length);
Now changed to stringBuilder();


回答1:


Your XML is correct (now that you have added the semi-colon), so your use of the SAX API must be wrong.

Maybe see the following answer: Sax parsing and encoding




回答2:


You need a semicolon (;) after the &amp:

<param>http://www.example.com?param1=abc&amp;v=1</param>

EDIT: Okay, now that this has been clarified a bit, I think the issue is that SAX doesn't have to return the entire string in a single characters() call. See this question for more information on how to resolve this.




回答3:


if ampv is param then:

<param>http://www.example.com?param1=abc&amp;ampv=1</param>

else if v is param:

<param>http://www.example.com?param1=abc&amp;v=1</param>


来源:https://stackoverflow.com/questions/6942999/proper-way-to-store-an-url-in-xml

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!