Arun Abraham
Arun Abraham

Reputation: 4047

XML Parsing issue in android

In a Nodelist.item[index].getChildNodes(), i am getting some junk values in between all the nodes like "#text", what could be the reason ? this is causing an error... Could anyone tell me any permanent fix for this.. is this some sort of namespace issue?

Upvotes: 2

Views: 329

Answers (4)

StaxMan
StaxMan

Reputation: 116620

Most likely that is white space someone uses indentation. It is not junk -- it is content like anything else, from XML parser's point of view.

But aside from this, if your code errors out due to this, your code is buggy. If you only want to access Elements, get just elements, or check type. You really should not assume things that are not necessarily true.

Upvotes: 0

Nacho L.
Nacho L.

Reputation: 9582

Try casting to Element the Node:

((Element)Nodelist.item[index]).getChildNodes().item(0).getNodeValue()

This would retrieve a the desired string.

Upvotes: 0

ns476
ns476

Reputation: 385

Simple is a fantastic library for XML parsing, I guarantee it'll make your life a whole load easier :)

Upvotes: 2

Rohit Sharma
Rohit Sharma

Reputation: 13825

Use SAXParser instead. it work simply great

http://java-samples.com/showtutorial.php?tutorialid=152

Upvotes: 1

Related Questions