Take the 2-minute tour ×

I observed that if you call sample StockQuoteService given in link, it gives following properly indented response :

<ns:getPriceResponse xmlns:ns="http://pojo.service.quickstart.samples/xsd">

I want response in specific XML format like

<answers>     // All answers should be in single `<answers>` tag.
  <answer> Answer1 </answer>   // Each Answer should be in `<answer>` tag.
  <answer> Answer2 </answer>

How can I format XML response and add my XML tag ?


share|improve this question
If I get you correctly, what you want to do is not necessarily SOAP. You might need to program the response manually. –  Martin Taleski Jul 22 '11 at 7:14
@Martin: Yes. Can you give me any idea how it can be done ? –  Karna Jul 22 '11 at 7:15
With Apache Axis, I am not sure, but I am not a great Java expert. Must you use Java? Will your services receive inputs, or they will be just outputting xml? –  Martin Taleski Jul 22 '11 at 7:19
I am using Java. My service takes on string input and should generate XML output. –  Karna Jul 22 '11 at 7:25
add comment

2 Answers

up vote 0 down vote accepted

Finally got it working http://www.marcusschiesser.de/?p=142 :)

share|improve this answer
add comment

You should use XSL Transformations (XSLT) to do this.

share|improve this answer
Thanks for the suggestion. But how can I remove <ns:getPriceResponse> and <ns:return> added by axis2 ? –  Karna Jul 22 '11 at 7:52
My answer is only for "How to edit / format XML response in web service". If you have a very specific need, you should precise your goals. If you want to do common things with web service response, maybe you just want to use JAXB objects ? –  Tristan Jul 22 '11 at 7:57
I have my mentioned my exact requirement in question with example of how the response should look like. By editing I also mean to remove some part which I already mentioned. Still let me know if I am missing anything. –  Karna Jul 22 '11 at 8:15
How do u think the only service answer "42" will become "Answer1" and "Answer2" for example ? –  Tristan Jul 22 '11 at 14:19
I apologize for the mistake. I want the answer in format mentioned above.each answer should be in <answer> tag with all answers in only one <answers> tag. Hope I am not confusing you anymore. –  Karna Jul 23 '11 at 6:41
show 2 more comments

Your Answer


