Hi,
Actually i'm developing a project in J2EE Env. And I've created a
XML File that stores the important data in elements. I want to
fetch those valeus and store them in to the JSP variables. How can
I do this? Is it possible to include XML File in JSP?
Thanks.
There are many ways to do this. In my opinion, the best thing to do would be to:
- Break down your xml structure into Java Objects. i.e.
<emp>
<name>
<first>jeebus</first>
<last>wally</last>
</name>
<address>
<line1>123 sesame st</line1>
<line2 />
<city>townsville</city>
<zip>22222</zip>
</address>
</emp>
This XML would correspond to:
public class Emp {
private Name name;
private Address address;
public emp() {}
// getters and setters
}
public class Name {
private String first;
private String last;
public Name() {}
// getters and setters
}
//...etc plus the address class
XMLBean will do this for you if your schema is huge, provided that you have an XSD. http://xmlbeans.apache.org/
Once all your parsing of the XML is done on the server side, you can store your java objects that represent the XML in the session, and later retrieving it in your JSP.
Hope that helps.