1

I'm trying to parse an XML feed using DOM. When a node looks like this:

<title>&#039;Star Wars&#039; May the force live</title>

the returned XML is only ' and then the parser continues on to the next node.

Here's how I'm parsing it:

NodeList list = node.getChildNodes();
    for (int j=0; j<list.getLength(); j++) {
        Node innerItem = list.item(j);
        String name = innerItem.getNodeName();

        if (name.equalsIgnoreCase("title")) {
            vo.setTitle(innerItem.getFirstChild().getNodeValue());
        }
    }

How can I fix this? The code parses fine in Android 4, but fails in Android 2.3.3

user123321
  • 12,593
  • 11
  • 52
  • 63

1 Answers1

2

Looks like your question is very much similar to this one: android decoding html in xml file

It seems HTML characters break the DOM parser, so it is unable to get the string from the xml entity. There is a HTML function to parse HTML in a string.

TextView tv;
String s = "<quote>&#039;Star Wars&#039; May the force live</quote>";
tv.setText(HTML.fromHtml(s));

Outputs:

"Star Wars" May the force live

However it seems the DOM isn't getting the string to convert, so the following article maybe useful: Using XPATH and HTML Cleaner to parse HTML/XML

Community
  • 1
  • 1
Shekhar Chikara
  • 3,786
  • 2
  • 29
  • 52