3

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();

sat
  • 40,138
  • 28
  • 93
  • 102

3 Answers3

3

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.

Community
  • 1
  • 1
Adam Batkin
  • 51,711
  • 9
  • 123
  • 115
3

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

Community
  • 1
  • 1
Matthew Wilson
  • 3,861
  • 21
  • 14
0

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>
Subdigger
  • 2,166
  • 3
  • 20
  • 42