sat
sat

Reputation: 41076

Proper way to store an url in xml?

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

Upvotes: 3

Views: 11235

Answers (3)

Adam Batkin
Adam Batkin

Reputation: 52994

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.

Upvotes: 3

Matthew Wilson
Matthew Wilson

Reputation: 3929

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

Upvotes: 3

Subdigger
Subdigger

Reputation: 2193

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>

Upvotes: 0

Related Questions