This discussion is archived
1 2 Previous Next 15 Replies Latest reply: Sep 21, 2012 12:56 PM by 939520 RSS

How to Convert ResultSet into XML and return that XML

Ajay Sharma Newbie
Currently Being Moderated
Hi..

I need to convert ResultSet into XML.

I am using DOM parser for this. Any other way to achieve it ?





Regards,
Ajay Sharma
  • 1. Re: How to Convert ResultSet into XML and return that XML
    EJP Guru
    Currently Being Moderated
    I need to convert ResultSet into XML.
    OK.
    I am using DOM parser for this.
    So you have a solution.
    Any other way to achieve it ?
    Why do you think you need another solution?
  • 2. Re: How to Convert ResultSet into XML and return that XML
    Ajay Sharma Newbie
    Currently Being Moderated
    Hi..

    I read many documents on internet. They mentioned DOM parser is easy to use but performance wise not good.

    Another thing is..
    I was testing through queries.
    when I fired a query and got the result set this result set contains 7600 rows..
    when I am converting using DOM parser and returning it, its taking approximate 10 sec for this.

    And some time not showing results..

    I am using this approach for my web service.

    I want to minimize the time.




    Regards,
    Ajay Sharma

    Edited by: Ajay Sharma on Sep 5, 2012 6:27 PM
  • 3. Re: How to Convert ResultSet into XML and return that XML
    EJP Guru
    Currently Being Moderated
    I read many documents on internet. They mentioned DOM parser is easy to use but performance wise not good.
    But you aren't using it as a parser. You're using it as a document builder.

    And what are your 'many documents' comparing it to?
  • 4. Re: How to Convert ResultSet into XML and return that XML
    Ajay Sharma Newbie
    Currently Being Moderated
    Hi..

    Many documents means information posted on Internet in the form of word file, pdf file or in forum

    Sorry Actually I don't know that converting Result Set into XML is not called as XML parsing.

    Is there any way to solve my issue ?


    Regards,
    Ajay
  • 5. Re: How to Convert ResultSet into XML and return that XML
    DrClap Expert
    Currently Being Moderated
    Reading an XML document and converting it to an internal form (like a DOM document for example) is called "parsing". The reverse process is called "serializing".

    Anyway, was this your issue?
    I want to minimize the time.
    In that case, first get the fastest possible computer. The one you're using is not adequate. And make sure to configure it so that no other applications are competing for resources. And make sure you get the fastest possible disk drives, and make sure there is plenty of empty disk space. You may want to consider whether some other operating system will be faster in terms of writing to disk.

    If you haven't already figured it out, "I want to minimize the time" is not a credible performance requirement. You're going to have to do better than that. My guess is that your present code is already fast enough, but you've been reading all of those articles on the web and now you feel guilty that your code takes all of two seconds to output the document.
  • 6. Re: How to Convert ResultSet into XML and return that XML
    EJP Guru
    Currently Being Moderated
    Is there any way to solve my issue ?
    It is yet to be shown that you even have an issue, and it is apparent that none of the articles you have read on the Internet is even valid: evidently none of them mentions an alternative, so they aren't comparing DOM to anything.

    Does it take ten seconds just to generate the document, or does that include the time to execute the query and fetch the seven thousand result rows and transmit it?

    I'm not aware of a better method to generate XML than using a DOM builder, and I see no reason why it should be considered slow. Is it possible that your code needs attention?
  • 7. Re: How to Convert ResultSet into XML and return that XML
    rp0428 Guru
    Currently Being Moderated
    >
    I need to convert ResultSet into XML.

    I am using DOM parser for this. Any other way to achieve it ?
    >
    Sure - Oracle database supports a wide range of XML functionality.

    Have Oracle return XML when you run the query.

    See the examples in the XML DB Developer's Guide
    http://docs.oracle.com/cd/B28359_01/appdev.111/b28369/xdb13gen.htm

    See DBMS_XMLGEN examples beginning with example 17-24.

    And you can use the SYS_XMLGEN package to query results directly using SQL. See examples beginning with Example 17-38.
    SELECT sys_XMLGen(
             dept_t(department_id,
                    department_name,
                    d.location_id,
                    CAST(MULTISET(SELECT emp_t(e.employee_id, e.last_name, e.job_id,
                                               e.manager_id, e.hire_date, e.salary,
                                               e.commission_pct)
                                    FROM hr.employees e
                                    WHERE e.department_id = d.department_id)
                         AS emplist_t))).getCLOBVal()
      AS deptxml
      FROM hr.departments d WHERE department_id = 10 OR department_id = 20;
  • 8. Re: How to Convert ResultSet into XML and return that XML
    Ajay Sharma Newbie
    Currently Being Moderated
    Hi..


    Yes, in 10 second it execute the given function, fetch the seven thousand result rows, transmit it, convert it to XML



    Regards,
    Ajay
  • 9. Re: How to Convert ResultSet into XML and return that XML
    EJP Guru
    Currently Being Moderated
    Exactly as I said. So far you have zero evidence that XML creation is the bottleneck. If you want to establish where the bottleneck is, you will have to accumulate times for each of those steps separately.
  • 10. Re: How to Convert ResultSet into XML and return that XML
    TPD-Opitz-Consulting-com Expert
    Currently Being Moderated
    How about using oracles XML-DB feature and getting it as a CLOB from database?

    bye
    TPD
  • 11. Re: How to Convert ResultSet into XML and return that XML
    Ajay Sharma Newbie
    Currently Being Moderated
    Hi..

    I got
    java.lang.OutOfMemoryError: Java heap space 
    while converting result set into XML format.

    I think it is because DOM parser use memory for xml tree creation.


    There is any way to either increase the Heap Size or Any other parser to convert Result Set into XML




    Regards,
    Ajay
  • 12. Re: How to Convert ResultSet into XML and return that XML
    Tolls Journeyer
    Currently Being Moderated
    Well, what do you want to do with the XML?
    If you just want to stream it to a file use rp0428's suggestion above and get the xml directly from Oracle, and stream that to wherever.

    If you need it as a DOM in memory then you'll need to give it more memory.

    Note that we have no idea what you are actually intending to use this XML for...
  • 13. Re: How to Convert ResultSet into XML and return that XML
    Ajay Sharma Newbie
    Currently Being Moderated
    Hi..

    I am using this in my web service.

    I need to send ResultSet data to Web Service Caller. So I am doing this operations.



    Reagrds,
    Ajay
  • 14. Re: How to Convert ResultSet into XML and return that XML
    rp0428 Guru
    Currently Being Moderated
    >
    I need to send ResultSet data to Web Service Caller. So I am doing this operations.
    >
    Use the method I gave you in my reply above.
    >
    Sure - Oracle database supports a wide range of XML functionality.

    Have Oracle return XML when you run the query.
1 2 Previous Next

Legend

  • Correct Answers - 10 points
  • Helpful Answers - 5 points