File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes XML and Related Technologies and the fly likes Error : Processing Instruction Target Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Engineering » XML and Related Technologies
Bookmark "Error : Processing Instruction Target" Watch "Error : Processing Instruction Target" New topic

Error : Processing Instruction Target

Rishi Tyagi
Ranch Hand

Joined: Feb 14, 2002
Posts: 100
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 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();
//**set content type
BufferedOutputStream os=new BufferedOutputStream(urlconn.getOutputStream());
//****write data to stream
BufferedInputStream is=new BufferedInputStream(urlconn.getInputStream());
//reading object
int i=readData(is);
System.out.println("Data received");
System.out.println("Data not received");
return retr_str;
//****************Test Code ends here
Madhav Lakkapragada
Ranch Hand

Joined: Jun 03, 2000
Posts: 5040
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

Take a Minute, Donate an Hour, Change a Life
William Brogden
Author and all-around good cowpoke

Joined: Mar 22, 2000
Posts: 13037
If you provide a catch for SAXParseException like this:

You can get the exact point in the stream that causes the error.
I agree. Here's the link:
subject: Error : Processing Instruction Target
jQuery in Action, 3rd edition