File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Web Services and the fly likes org.xml.sax.SAXParseException 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 » Java » Web Services
Bookmark "org.xml.sax.SAXParseException" Watch "org.xml.sax.SAXParseException" New topic


kundan varma
Ranch Hand

Joined: Mar 08, 2004
Posts: 323
Hi All,
I am having "org.xml.sax.SAXParseException: Document root element is missing" . The jaxp parser is giving me this error....
I am generating XML from this code
private void setAttachment() throws SOAPException,FileNotFoundException,IOException {
MessageFactory mf = MessageFactory.newInstance();
SOAPMessage message = mf.createMessage();
File imgFile = new File("D:\\Pics\\Me\\Image(067).jpg");
FileInputStream fis = new FileInputStream(imgFile);
String path = imgFile.getAbsolutePath();
//Image image = Toolkit.getDefaultToolkit().createImage(path);
AttachmentPart jpegAttach = message.createAttachmentPart();

File file = new File("c:\\test\\Attachment.xml");
path = file.getAbsolutePath();
FileOutputStream fos = new FileOutputStream(path);

I am using AXIS also.

The XML which is generated from this is given below


Content-Type: text/xml; charset=UTF-8

Content-Transfer-Encoding: binary

Content-Id: <B27FA6C4D8C823D8C4E0D436AE26D03E>

<?xml version="1.0" encoding="UTF-8"?>
<soapenv:Envelope xmlns:soapenv="" xmlns:xsd="" xmlns:xsi="">


Content-Type: image/jpeg

Content-Transfer-Encoding: binary

Content-Id: <E54FA2EDDCB0638BECAB9DC415090341>


Please advise what can be wrong here.

Failures are practice shoots for success.
Peer Reynders

Joined: Aug 19, 2005
Posts: 2933
Originally posted by kundan varma:
The XML which is generated from this is given below

That's not XML. It's a MIME envelope where the first part contains the SOAP message (which is the XML). That is what is supposed to happen for "SOAP with Attachments" which have to be treated separately from regular SOAP messages.

You may want to have a look at the end of
Java Web Services in a Nutshell Chapter 3: SAAJ
"SOAP Messages and MIME Headers"
"SOAP with Attachments"
and Sending SOAP attachments with JAX-RPC
I agree. Here's the link:
subject: org.xml.sax.SAXParseException
jQuery in Action, 3rd edition