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 XML over HTTP? 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 "XML over HTTP?" Watch "XML over HTTP?" New topic

XML over HTTP?

Joshua Lam

Joined: Apr 12, 2000
Posts: 14
What is the best way to send XML over HTTP? ie do we send it as a name/value pair? (ie the value being the whole XML doc?)
Tony Alicea

Joined: Jan 30, 2000
Posts: 3226
I don't understand the question but I think theres a MIME type text/xml. I don't see why it has to be treated differently. For example, a GET is a GET is a GET.
Or maybe I don't understand the question...

Tony Alicea
Senior Java Web Application Developer, SCPJ2, SCWCD
Joshua Lam

Joined: Apr 12, 2000
Posts: 14
Sorry to be vague. Ok, let me try again:
What is the best way for a Java client use HTTP to POST an XML document to a Java http servlet? Should the Java client send the XML document as a whole document or as a name/value pair?
If it is sent as a name value/pair eg 'xmldoc=<the xml doc>' then the http servlet can retrieve the document by using getParameter("xmldoc") which return the content xml document.
Is this an efficient way? What are other ways? Are there XML/Http libraries out there that does this?
Edward Man
Ranch Hand

Joined: May 16, 2000
Posts: 40
One of the popular free XML parsers is IBM's XML for Java (XML4J). It supports both DOM and SAX. You can use it with servlet. You can get it here.
My suggestion is to send the XML document (with DTD perhaps?) to the servlet and let the servlet parse the XML document and retrieve the data.
Frank Carver

Joined: Jan 07, 1999
Posts: 6920
It depends if you intend to send any other data along with the XML. If your client/browser also needs to send cookies, hidden form fields, etc. etc. then you may need to use the name=value method. This is a "safe" approach, but can be considerably less efficient than sending "raw" XML over the HTML stream.
Using name=value in a GET request is risky because some servers, proxies, firewalls etc. might restrict or truncate the length of a GET request, so it's inappropriate for flexible data format like XML.
Using name=value in a POST request incurs the penalty of URL-escaping the data at the client and unescaping it at the server, even though XML has its own processes for that.
The most efficient method is to send the XML as the only data over the stream and have a custom servlet to read the input. You may also want to use some form of "content-length" to simplify reading the data at the server end.
Conceptually XML should be an alternative HTML request format, understood by servers and clients so you could say something like
<form action=/myapp/servlet/something method=XML>
blah ...
but until that becomes popular, you have to roll your own.

Read about me at ~ Raspberry Alpha Omega ~ Frank's Punchbarrel Blog
Swapan Mazumdar
Ranch Hand

Joined: Jul 23, 2003
Posts: 83
Hi All,

I need to implement xml over http to send request as xml to a payment gateway i.e https://www.payment.server/pay.asp and process the response coming as xml back to the client.

Does Apache XML-RPC is an answer to this?
Please share any other java implementation technologies suitable for this requirement and tried and tested.

best rgrds
I agree. Here's the link:
subject: XML over HTTP?
jQuery in Action, 3rd edition