-
I am writing a bean that fetches rows from a database, formats it, and returns an xml file. I dont understand how i can return an xml file. Obviously it cant be a file object. One thought was to recieve a file object as an argument and write into the file. Is there a more elegant way of doing this? I would greatly appreciate any advise.
-
You really don’t return a File object; rather you would return a Document object. (i.e.) “org.w3c.dom.Document” obj. The following code creates an XML doc of the following hierarchy.
D (Document)
|
+--Some_Info (Child Node)
|
+Name (Leaf Node)
+Age
+SomeValue
private org.w3c.dom.Document getXMLFile() {
int someAge = 45;
double someValue = 125.52;
String someName = "Anonymous";
String domImplementation = "com.ibm.xml.parser.TXDocument";
org.w3c.dom.Document d = (org.w3c.dom.Document) Class.forName(domImplementation).newInstance();
org.w3c.dom.Element xRecord = d.createElement("Some_Info");
org.w3c.dom.Element xName = d.createElement("Name");
Text xNameValue = d.createTextNode(someName);
xRecord.appendChild(xDateValue);
org.w3c.dom.Element xAge = d.createElement("Age");
Text xAgeValue = d.createTextNode(String.valueOf(someAge));
xRecord.appendChild(xAgeValue);
org.w3c.dom.Element xsomeValue = d.createElement("Some_Value");
Text xSomeValue = d.createTextNode(String.valueOf(someValue));
xRecord.appendChild(xSomeValue);
d.appendChild(xRecord);
// More Records
:
:
:
return d;
}
Hope this helps. Any other methods welcome!
-
asdfsdafsd
-
Send the XML over JMS As a Message and have a MDB listen on it at the other end
Zimble
Sahil
-
if you are using oracle try XSU utility from oracle.