aspose file tools*
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
JavaRanch » Java Forums » Engineering » XML and Related Technologies
Bookmark "Error : Processing Instruction Target" Watch "Error : Processing Instruction Target" New topic
Author

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 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

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
http://www.ashanet.org/workanhour/2006/?r=Javaranch_ML&a=81
William Brogden
Author and all-around good cowpoke
Rancher

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

You can get the exact point in the stream that causes the error.
Bill
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Error : Processing Instruction Target