0

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.

David
  • 2,103
  • 3
  • 21
  • 29

2 Answers2

1

see this answer here

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

Community
  • 1
  • 1
Paul Whelan
  • 16,574
  • 12
  • 50
  • 83
1

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

Community
  • 1
  • 1
dave.c
  • 10,910
  • 5
  • 39
  • 62