Returning an XML file


EJB design: Returning an XML file

  1. Returning an XML file (4 messages)

    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.

    Threaded Messages (4)

  2. Returning an XML file[ Go to top ]

    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)

    private org.w3c.dom.Document getXMLFile() {
    int someAge = 45;
    double someValue = 125.52;
    String someName = "Anonymous";
    String domImplementation = "";

    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);
    org.w3c.dom.Element xAge = d.createElement("Age");
    Text xAgeValue = d.createTextNode(String.valueOf(someAge));
    org.w3c.dom.Element xsomeValue = d.createElement("Some_Value");
    Text xSomeValue = d.createTextNode(String.valueOf(someValue));
    // More Records

    return d;

    Hope this helps. Any other methods welcome!
  3. Returning an XML file[ Go to top ]

  4. Returning an XML file[ Go to top ]

    Send the XML over JMS As a Message and have a MDB listen on it at the other end
  5. Returning an XML file[ Go to top ]

    if you are using oracle try XSU utility from oracle.