Denis Kutlubaev
Denis Kutlubaev

Reputation: 16174

Ampersand in URL while parsing XML in Android

I have a problem. I parse XML. There is URL in that XML, that looks like this:

<link>http://basa.med-info.ru/xse/index.php?query=грипп&amp;cluster=9025</link>

When this link is parsed, using this code:

NodeList linkList = drugElement.getElementsByTagName("link");
            Element linkElement = (Element)linkList.item(0);
            NodeList textLinkList = linkElement.getChildNodes();
            link = textLinkList.item(0).getNodeValue().trim();
            Log.i(TAG, "link: "+link);

the result is this:

link: http://basa.med-info.ru/xse/index.php?query=грипп

So, for some reason the rest of URL is lost: &cluster=9025 How to solve it?

Update True code is this:

NodeList linkList = drugElement.getElementsByTagName("link");
            Element linkElement = (Element)linkList.item(0);
            NodeList textLinkList = linkElement.getChildNodes();
            link = "";
            for (int j = 0; j < textLinkList.getLength(); j++)
            {
                    link += textLinkList.item(j).getNodeValue();
            }
            Log.i(TAG, "link: "+link);

Upvotes: 0

Views: 474

Answers (1)

Don Roby
Don Roby

Reputation: 41135

You have

        link = textLinkList.item(0).getNodeValue().trim();

thus explicitly getting the text only from the first text node in your <link>.

Most likely the rest of the text is in successive items in textLinkList.

Upvotes: 1

Related Questions