This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes XML and Related Technologies and the fly likes Attachment Element Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Engineering » XML and Related Technologies
Bookmark "Attachment Element" Watch "Attachment Element" New topic
Author

Attachment Element

Brian Podolny
Ranch Hand

Joined: Aug 29, 2000
Posts: 32
I've been tasked with writing a java mailer / webservice to simplify sending emails from within our applications.
The mailer will have a function, sendMail() which will take an xml document as a String parameter. The xml document will contain all of the message info (i.e. sender, recips, message body, etc).
I'm stumped on what would be the best way to include any attachments within the mail doc. Any idea's?
Here are my thoughts:
I'm thinking I will include an <attachmentlist> element which will contain 1 <attachment> element for each attachment for the email. However, I don't know how to write a file as the data for an element and I don't know how I will extract that data and put it into a multipart message.
Thanks!
Balaji Loganathan
author and deputy
Bartender

Joined: Jul 13, 2001
Posts: 3150
If you decided to use webservice
My idea could be to convert the file in to a byte array (base64Binary) as one element and file extension as one element.
The server will convert the byte array into a file with the given file extension and send it as an attachement to the user.
But you have to decide whether you need a webservice to do this task according to your requirements


Spritle Software Blogs
Brian Podolny
Ranch Hand

Joined: Aug 29, 2000
Posts: 32
I think that will work. I might include the file extension as an attribute of the attachment element rather than as a separate element. I could probably include the encoding type as an attribute as well - to increase flexibility. What do youy think?
The main point of the mailer as a webservice is for applications to have a simple and common way to send notification messages. File attachments will rarely be used but I think I need to plan for them. Unfortunately, forcing the developer to encode attachments and then embed them into an xml doc in order to use the webservice, doesn't really simplify things for the developer at all.
Thanks again!
Balaji Loganathan
author and deputy
Bartender

Joined: Jul 13, 2001
Posts: 3150
Originally posted by Brian Podolny:
Unfortunately, forcing the developer to encode attachments and then embed them into an xml doc in order to use the webservice, doesn't really simplify things for the developer at all.
Thanks again!

Well!..
In that case you can supply a sample code fragement for both java/microsoft clients, or a sort of small tutorial may also attract them.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Attachment Element
 
Similar Threads
Referring to namespace in xml document
Clarification sought on the Basic profile
How to make an element value unique within entire instance document?
HTML content for a Markup
JAXP transformations