File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

org.xml.sax.SAXParseException

 
kundan varma
Ranch Hand
Posts: 323
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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();
jpegAttach.setContent(fis,"image/jpeg");
message.addAttachmentPart(jpegAttach);

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

I am using AXIS also.


The XML which is generated from this is given below


------=_Part_0_17876004.1140606394046

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="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<soapenv:Body/>
</soapenv:Envelope>

------=_Part_0_17876004.1140606394046

Content-Type: image/jpeg

Content-Transfer-Encoding: binary

Content-Id: <E54FA2EDDCB0638BECAB9DC415090341>



����


Please advise what can be wrong here.
Thanks,
kundan
 
Peer Reynders
Bartender
Posts: 2936
5
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic