Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Error : Processing Instruction Target

 
Rishi Tyagi
Ranch Hand
Posts: 102
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,
I am new to xml and trying to make a Servlet which receives xml data in input
Now the Aim of this application is
1- It will receive the data in XML Format
2- Now it will extract the data enclosed with in the xml tags
3- will save data into the database
I have also made one test application which send the xml data to this servlet by making connection by java.net.URLConnection class and writes data using Stream and reading data into the servlet using the stream but servlet respond with the following Error :
errror ---org.xml.sax.SAXParseException: Processing instruction target is missing
I could not understand the problem
Here is the code which i am using to read parse the xml data in the servlet, Error comes at line no 7 (using of parse method) in the code given below
//***************Servlet Code starts here
1) DocumentBuilderFactory dbf =DocumentBuilderFactory.newInstance();
2) dbf.setNamespaceAware(true);
3) dbf.setIgnoringComments(true);
4) dbf.setIgnoringElementContentWhitespace(true);
5) dbf.setCoalescing(true);
6) DocumentBuilder db = dbf.newDocumentBuilder();
7) Document doc = db.parse(rq.getInputStream());//here rq=HttpServletRequest parameter in service method of servlet
//*************Servlet code end here
code of this Test application is
//*********TestApp Code starts here
public String sendToServlet(String path,String str) throws Exception
{
String retr_str="";
URL url=new URL(path);
URLConnection urlconn=url.openConnection();
urlconn.setUseCaches(false);
//**set content type
urlconn.setRequestProperty("CONTENT_TYPE","text/xml");
urlconn.setDoInput(true);
urlconn.setDoOutput(true);
BufferedOutputStream os=new BufferedOutputStream(urlconn.getOutputStream());
//****write data to stream
os.write(str.getBytes());
os.flush();
os.close();
BufferedInputStream is=new BufferedInputStream(urlconn.getInputStream());
//reading object
int i=readData(is);
if(i>0)
{
System.out.println("Data received");
}
else
{
System.out.println("Data not received");
}
retr_str=xmlString;
is.close();
return retr_str;
}
//****************Test Code ends here
 
Madhav Lakkapragada
Ranch Hand
Posts: 5040
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
7) Document doc = db.parse(rq.getInputStream());//here rq=HttpServletRequest parameter in service method of servlet

Before parsing, try to print the rq stuff and check to see what kinda xml you are getting ?
Based on that you can decide where the error is cropping up ?
- madhav
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13062
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you provide a catch for SAXParseException like this:

You can get the exact point in the stream that causes the error.
Bill
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic