David
David

Reputation: 2131

DOM Parser issues in Android?

In my application i am using DOM parser to parse XML. The DOM parser giving 100% result by using without any space in the URL string . If anything blank space in my URL string i am getting error like org.xml.sax.SAXParseException: Unexpected end of document This is my url string "www.someurl.com/queryType=new-celeb&name=ABC&category=American Foot ball". In the above url string there was blank space (American Foot ball)in category attribute so i am receiving exception. without blank space its working.

this is my piece of code

URL url= new URL("www.someurl.com/queryType=new-celeb&name=ABC&category=American Foot ball");           
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
DocumentBuilder db = dbf.newDocumentBuilder();
Document doc = db.parse(new InputSource(url.openStream()));
doc.getDocumentElement().normalize();
Element ele=doc.getDocumentElement();
NodeList nodeList = ele.getElementsByTagName("items");

Give me some idea to solve my problem.

Upvotes: 0

Views: 712

Answers (2)

dave.c
dave.c

Reputation: 10908

A space is not a valid character for a URL, it should be encoded. Have a look at the answers to this question

Upvotes: 1

Paul Whelan
Paul Whelan

Reputation: 16809

see this answer here

Sounds like it may relevant. It escapes the spaces in urls

Upvotes: 1

Related Questions