cancel
Showing results for 
Search instead for 
Did you mean: 

How to parse the xml file using servlet

Former Member
0 Kudos

My scenario is like this:

<b>FILE-->XI-->J2EE Application</b>

XI sends the xml file to j2ee application. My servlet receives the file in HTTPRequest string.

How to parse that file using servlets.I should get the xml file as it is and should be displayed in the browser.

Can anyone please help me with code, its urgent.

Please help me!

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

You can use the <b>Echo</b> Sax parsing program on sun website to emit the request xml as it is

http://java.sun.com/webservices/jaxp/dist/1.1/docs/tutorial/sax/2a_echo.html

and the inputstream to feed to the SAX parser instnace could be recieved as

request.getInputStream());

Rgds,

Amol

Former Member
0 Kudos

Hi Amol!

Thanks for the inputs. How to get the values from request object and how to construct the xml again using servlets.

The file i receive from XI will be like this:

<ns0:Http_Message_Type_Demo xmlns:ns0="http://abcdemo.com">

<Name>abc</Name>

<RollNo>123</RollNo>

<Address>a-2</Address>

</ns0:Http_Message_Type_Demo>

as you see here the xml file contains values.How to retrieve these values using servlets and construct the xml file as it is with the same structure.Its urgent your help will be greatly appreciated.

Thanks in advance!

Former Member
0 Kudos

Download this java code

http://java.sun.com/webservices/jaxp/dist/1.1/docs/tutorial/sax/work/Echo02.java

in your servlet code you can write

public void doPost(req,resp){
..
DefaultHandler handler = new Echo02();
handler.parse(req.getInputStream());
..
}

Offcourse you will need to modify the code of Echo02 class a bit to suit your requirement which would finally retrun you a string and you can then write it using

respose.getWriter().write(responseString);

}

Answers (0)