Hello All,
Greetings!
I am trying to play around with a XML document. In my
java code -
I pass the XML document path from my
JSP. I am creating a FILE object and then using DocumentBuilderFactory, DocumentBuilder I parse the XML into a Document object. Code snippet-
************************************
public static Document RetrieveXML(
String filename) {
String ret = null;
Document
doc;
try {
File file = new File(filename);
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
DocumentBuilder db = dbf.newDocumentBuilder();
doc = db.parse(file);
doc.getDocumentElement().normalize();
}
catch(Exception e){
e.printStackTrace();
}
return(doc);
}
************************************
Now in my RetrieveXML method, I want to return the Document object so that I can pass it to other methods from my jsp for setting/getting Element value, attribute value. For eg: In this method I want to set the value of an element. I am passing the parsed XML document from above.
public static void setElementValue(Document xmldoc,String strElement,String strValue){}
The problem is that, RetrieveXML does not return the Document object. It is throwing an error. Any idea why?
Is my approach wrong? Any help in this regard will be highly appreciated!
Thanks in Advance,
Best Wishes,
Sumon