Generating XML from SQL queries and saving to a xml file?

Hi there,
I was wondering if somebody could help with regards to the following:
Generating XML from SQL queries and saving to a xml file?
We want to have a stored procedure(PL/SQL) that accepts an order number as an input parameter(the procedure
is accessed by our software on the client machine).
Using this order number we do a couple of SQL queries.
My first question: What would be our best option to convert the result of the
queries to xml?
Second Question: Once the XML has been generated, how do we save that XML to a file?
(The XML file is going to be saved on the file system of the server that
the database is running on.)
Now our procedure will also have a output parameter which returns the filename to us. eg. Order1001.xml
Our software on the client machine will then ftp this XML file(based on the output parameter[filename]) to
the client hard drive.
Any information would be greatly appreciated.
Thanking you,
Francois

Hi
Here is an example of some code that i am using on Oracle 817.
The create_file procedure is the one that creates the file.
The orher procedures are utility procedures that can be used with any XML file.
PROCEDURE create_file_with_root(po_xmldoc OUT xmldom.DOMDocument,
pi_root_tag IN VARCHAR2,
                                        po_root_element OUT xmldom.domelement,
                                        po_root_node OUT xmldom.domnode,
                                        pi_doctype_url IN VARCHAR2) IS
xmldoc xmldom.DOMDocument;
root xmldom.domnode;
root_node xmldom.domnode;
root_element xmldom.domelement;
record_node xmldom.domnode;
newelenode xmldom.DOMNode;
BEGIN
xmldoc := xmldom.newDOMDocument;
xmldom.setVersion(xmldoc, '1.0');
xmldom.setDoctype(xmldoc, pi_root_tag, pi_doctype_url,'');
-- Create the root --
root := xmldom.makeNode(xmldoc);
-- Create the root element in the file --
create_element_and_append(xmldoc, pi_root_tag, root, root_element, root_node);
po_xmldoc := xmldoc;
po_root_node := root_node;
po_root_element := root_element;
END create_file_with_root;
PROCEDURE create_element_and_append(pi_xmldoc IN OUT xmldom.DOMDocument,
pi_element_name IN VARCHAR2,
                                        pi_parent_node IN xmldom.domnode,
                                        po_new_element OUT xmldom.domelement,
                                        po_new_node OUT xmldom.domnode) IS
element xmldom.domelement;
child_node xmldom.domnode;
newelenode xmldom.DOMNode;
BEGIN
element := xmldom.createElement(pi_xmldoc, pi_element_name);
child_node := xmldom.makeNode(element);
-- Append the new node to the parent --
newelenode := xmldom.appendchild(pi_parent_node, child_node);
po_new_node := child_node;
po_new_element := element;
END create_element_and_append;
FUNCTION create_text_element(pio_xmldoc IN OUT xmldom.DOMDocument, pi_element_name IN VARCHAR2,
pi_element_data IN VARCHAR2, pi_parent_node IN xmldom.domnode) RETURN xmldom.domnode IS
parent_node xmldom.domnode;                                   
child_node xmldom.domnode;
child_element xmldom.domelement;
newelenode xmldom.DOMNode;
textele xmldom.DOMText;
compnode xmldom.DOMNode;
BEGIN
create_element_and_append(pio_xmldoc, pi_element_name, pi_parent_node, child_element, child_node);
parent_node := child_node;
-- Create a text node --
textele := xmldom.createTextNode(pio_xmldoc, pi_element_data);
child_node := xmldom.makeNode(textele);
-- Link the text node to the new node --
compnode := xmldom.appendChild(parent_node, child_node);
RETURN newelenode;
END create_text_element;
PROCEDURE create_file IS
xmldoc xmldom.DOMDocument;
root_node xmldom.domnode;
xml_doctype xmldom.DOMDocumentType;
root_element xmldom.domelement;
record_element xmldom.domelement;
record_node xmldom.domnode;
parent_node xmldom.domnode;
child_node xmldom.domnode;
newelenode xmldom.DOMNode;
textele xmldom.DOMText;
compnode xmldom.DOMNode;
BEGIN
xmldoc := xmldom.newDOMDocument;
xmldom.setVersion(xmldoc, '1.0');
create_file_with_root(xmldoc, 'root', root_element, root_node, 'test.dtd');
xmldom.setAttribute(root_element, 'interface_type', 'EXCHANGE_RATES');
-- Create the record element in the file --
create_element_and_append(xmldoc, 'record', root_node, record_element, record_node);
parent_node := create_text_element(xmldoc, 'title', 'Mr', record_node);
parent_node := create_text_element(xmldoc, 'name', 'Joe', record_node);
parent_node := create_text_element(xmldoc,'surname', 'Blogs', record_node);
-- Create the record element in the file --
create_element_and_append(xmldoc, 'record', root_node, record_element, record_node);
parent_node := create_text_element(xmldoc, 'title', 'Mrs', record_node);
parent_node := create_text_element(xmldoc, 'name', 'A', record_node);
parent_node := create_text_element(xmldoc, 'surname', 'B', record_node);
-- write the newly created dom document into the buffer assuming it is less than 32K
xmldom.writeTofile(xmldoc, 'c:\laiki\willow_data\test.xml');
EXCEPTION
WHEN xmldom.INDEX_SIZE_ERR THEN
RAISE_APPLICATION_ERROR(-20120, 'Index Size error');
WHEN xmldom.DOMSTRING_SIZE_ERR THEN
RAISE_APPLICATION_ERROR(-20120, 'String Size error');
WHEN xmldom.HIERARCHY_REQUEST_ERR THEN
RAISE_APPLICATION_ERROR(-20120, 'Hierarchy request error');
WHEN xmldom.WRONG_DOCUMENT_ERR THEN
RAISE_APPLICATION_ERROR(-20120, 'Wrong doc error');
WHEN xmldom.INVALID_CHARACTER_ERR THEN
RAISE_APPLICATION_ERROR(-20120, 'Invalid Char error');
WHEN xmldom.NO_DATA_ALLOWED_ERR THEN
RAISE_APPLICATION_ERROR(-20120, 'Nod data allowed error');
WHEN xmldom.NO_MODIFICATION_ALLOWED_ERR THEN
RAISE_APPLICATION_ERROR(-20120, 'No mod allowed error');
WHEN xmldom.NOT_FOUND_ERR THEN
RAISE_APPLICATION_ERROR(-20120, 'Not found error');
WHEN xmldom.NOT_SUPPORTED_ERR THEN
RAISE_APPLICATION_ERROR(-20120, 'Not supported error');
WHEN xmldom.INUSE_ATTRIBUTE_ERR THEN
RAISE_APPLICATION_ERROR(-20120, 'In use attr error');
WHEN OTHERS THEN
dbms_output.put_line('exception occured' || SQLCODE || SUBSTR(SQLERRM, 1, 100));
END create_file;

Similar Messages

  • Generating XML from SQL queries and saving to an xml file?

    Hi there,
    I was wondering if somebody could help with regards to the following:
    Generating XML from SQL queries and saving to a xml file?
    We want to have a procedure(PL/SQL) that accepts an order number as an input parameter(the procedure
    is accessed by our software on the client machine).
    Using this order number we do a couple of SQL queries.
    My first question: What would be our best option to convert the result of the
    queries to xml?
    Second Question: Once the XML has been generated, how do we save that XML to a file?
    (The XML file is going to be saved on the file system of the server that
    the database is running on.)
    Now our procedure will also have a output parameter which returns the filename to us. eg. Order1001.xml
    Our software on the client machine will then ftp this XML file(based on the output parameter[filename]) to
    the client hard drive.
    Any information would be greatly appreciated.
    Thanking you,
    Francois

    If you are using 9iR2 you do not need to do any of this..
    You can create an XML as an XMLType using the new SQL/XML operators. You can insert this XML into the XML DB repository using DBMS_XDB.createResource. You can then access the document from the resource. You can also return the XMLType containing the XML directly from the PL/SQL Procedure.

  • How to generate XML file from SQL file !

    I am new to XML publisher. I known one way to generate XML file is register one report file in concurrent manager.
    But I want to generate XML file from sql file.
    Could someone show me how to code in sql file, how to register is in concurrent manager.
    Thanks !

    Hi
    Phew ... not sure we have the space here. So I can point you in the right direction:
    1. XML data generation - there are two packages in the db you can use with a plsql procedure, XMLGEN and SQL XML. You can also use java APIs too. Try checking the db documentation and search for the above methods.
    2. Registering the report - the system administrators guide will provide this info. Hooking the program up with XMLP is covered here - http://www.oracle.com/technology/products/applications/publishing/resource/CM%20Whitepaper5.0.pdf
    Regards, Tim

  • Generate XML File from table

    How to generate XML file from a table without using UTL_FILE that too in local machine...

    You downloaded the wrong XML Parser!
    XSQL requires Java Parser. Well, there's a copy included with the XSQL package so you actually don't need to do another download.
    You really don't need XSQL if you just want a XML file from DB, you just needed a XML SQL Utility. Download that and run the samples.

  • Error while generating XML file from rdf report.

    Hi All,
    we are having a rdf report that displays images retrieved from data base. I need to convert this report to xml report(using rtf template).
    when i tried to run the report after changing the output of the concurrent program to "XML", i am getting the below error.
    REP-1295: Data format of column 'PK1_VALUE' is unsupported.
    REP-0069: Internal error
    REP-57054: In-process job terminated:Terminated with error:
    REP-1295: Data format of column 'PK1_VALUE' is unsupported.
    images are stored in BLOB type columns.
    Can anyone help me on this..
    thanks
    gtungala

    Hi Hussein,
    Thank you for the reply.. i was sure that i will get correct response with in a day..
    you people made this as one of the best technical forums..no doubt in that..
    need some more help from you...!
    The metalink docs say that it is not possible to generate xml file as the image is BLOB.
    Can you please tell me any solution for developing xml template(rtf) which can display images that are stored in data base BLOB columns. Even PL/SQL script will do.. I have tried with changing the BLOB to CLOB in rdf query(by calling a function that converts BLOB to CLOB). it didnt help.
    thanks in advance..
    gtungala

  • Generate XML file from RFC using Web Services

    Hi,
      I am trying to save an RFC enabled Function Module output to an XML file using ABAP web services.
    I could able to create Web Service and release it using WSCONFIG/WSADMIN. I can actually get the output in XML file when i launch the web service home page. But I need this to be done in the ABAP program itself. So If i run the RFC I could able to create,release web service and capture the Generated XML file by SOAP runtime.
    Any FM available?
    Thanks,
    Ram Sanjeev

    which version of WAS you are on .
    if you are on WAS6.40 check the following weblog on how to consume webservice using the wsdl file.
    /people/thomas.jung3/blog/2004/11/17/bsp-a-developers-journal-part-xiv--consuming-webservices-with-abap
    lower version of WAS use class cl_http_client.
    if this case you have to manually build the soap message.
    /people/durairaj.athavanraja/blog/2004/09/20/consuming-web-service-from-abap
    Regards
    Raja

  • Generating XML file from WORD file

    hello
    Everyboby.
    I am trying to generate xml file from a word file.
    but i am stucked with how to do it? any kind of help will be useful.
    i think for doing this work i have to develop XSD file, because when i am creating the xml file, the hidden space within the word file is not catched.
    please help me out.
    waiting for reply
    thanks
    milind

    hello
    after searching on the net i came to know that org.apache.poi.hwpf.* is used for reading word file and its contents. for converting it to xml i have to use org.exolab.castor.xml.*
    now my problem is that POI is in its early beta version and there is no help or any sample examples for understanding the api.
    so if you have any idea regarding it, please write to me.
    waiting for your reply.
    thanks
    Milind

  • Java code to generate XML File from XML Schema

    Hi I need this asap... "Java code to generate XML File from XML Schema i.e XML Schema Definition, XSD file".
    Thankz in advance...

    JAXB has been available as an early release download for some time. There are also XML Binding packages available from Borland (JBuilder) and Castor. These tools create Java classes from a source document, xml,dtd etc. You can use these classes to marshal-unmarshal XML documents.
    Dave

  • Generate XML file from Billing Output

    Hello,
    We have a business requirement to generate XML file from billing output and the same needs to send to external system for document printing.  In this regard, could you please guide the steps to configure or share the document on how the system to be configured to support the XML file generation from billing document.
    Anticipating a positive reply
    Thanks in advance
    Best Regards,
    Goutham

    another  option is to configure an outbound IDOC and set the port for this IDOC to generate an XML file.
    here again there will be IDOC control record in the first section of the IDOC XML generated.'
    rgds

  • How can I stop music and movies from being automatically deleted from my phone and saved on the cloud? I've just tried to watch a movie on my 2 hour commute, but yet AGAIN it has been removed. I do NOT want to spank all of my data allowance

    How can I stop music and movies from being automatically deleted from my phone and saved on the cloud? I've just tried to watch a movie on my 2 hour commute, but yet AGAIN it has been removed. I do NOT want to spank all of my data allowance downloading it again, especially because (believe it or not) I added it to my phone because that's precisely where I wanted it!! Any help much appreciated

    FYI I had to put this link into firefox to reply - because **** back safari just wouldn't register my clicks to any of the links on the post... Despite reloadeing and even restarting my computer. Totally annoying and a massive pain in the ***.
    But in terms of my initial query; thanks for responding. But no, this is NOT the cause of the problem. I have auto sync and sync over wifi activated, but have also selected manually manage music and videos. Plus, all of my music and videos are on my macbook, absolutely all of it, so if it my phone was syncing with my macbook everything would still be on the phone. Life would be peachy if my phone jsut copied everything that was on my macbook, but unfortuantely it keeps deleting tracks for no apparent reason.
    Any thoughts greatly welcomed, because at the moment i can only conclude that my iphone is crap.

  • Pull data from SQL Table and display it in mail

    I have a requirement to pull the data from SQL table and send it in email.  Currently I am sending the hard coded info in email but is it possible to pull some data from SQL Table and than format it and send it across in the same email? 
    Can you guide me with steps on this.
    Neil

    There are several ways to do this.  First is to populate a file in a data flow and then send that as an attachment in the send mail task. 
    As far as including the results in the email body this becomes a bit trickier.  To use a variable you would need to use an SSIS variable type of
    Object, this is similar to a collection in .NET.  The problem once the object is populated is that it isn't like a readable result set, but again more like an array or a collection.  There is no native method to take the object variable and
    specify .ToString() or cast its results as text.  You would need to iterate through each row and append it to another variable of type string, this could be done with a script task or ForEach container.
    Also you mentioned formatting the results.  What type of formatting were you looking for.  A limitation of the SMTP send mail task is that the message body doesn't support HTML so if you were looking at creating a table within the mail body you
    would have to use a script task or a custom component
    David Dye My Blog

  • Hi I need this asap... "Java code to generate XML File from XML Schema"

    Hi all....
    I need this asap... "Java code to generate XML File from XML Schema i.e XML Schema Definition, XSD file".
    Thankz in advance...
    PS: I already posted in the afternoon... this is the second posting.

    take look at :
    http://sourceforge.net/projects/jaxme/
    this might help...

  • HT1473 i have downloaded some songs from the internet and saved it on my desktop. how do i transfer those songs to itunes?

    i have downloaded some songs from the internet and saved it on my desktop. but i do not know how to import the songs from that folder to itunes.

    Just drag the song(s) to iTunes, if they are one of these formats (wav, m4a, mp3, mp4, wma etc) and they will appear under Music library.
    If you have lots of music files, put them in a folder and go iTunes menu FILE, Add folder to library..... to add this folder at one go.

  • Error while generating XML file through RDF

    Hi,
    I wanted to generate a Report on some business case. For that I need to generate XML file first.
    For generating XML file
    1. I have built an RDF through Reports builder.
    2. Saved the report to local machine with extension .rdf
    3. Moved it to appltop/app/reports/US directory
    4. Registered tha Report with Executable of type Oracle Reports
    5. Defined Concurrent Program with OUTPUT as XML.
    When I submmitted the program, it was giving an error as follows.
    The XML page cannot be displayed
    Cannot view XML input using style sheet. Please correct the error and then click the Refresh button, or try again later.
    A semi colon character was expected. Error processing resource 'https://oaphrd.humana.com/OA_CGI/FNDWRR.exe?temp_id=2088989...
    +<?xml version="1.0" encoding="&Encoding"?>+
    But, when I tried to sane the report directly to a file (file - > generate file -> XML) the XML was generated successfully.
    How to get rid of this. Some one please help me out.
    Thanks !
    Edited by: Rajasekhar Reddy on May 4, 2012 1:23 AM

    Hi,
    I found the issue and corrected it. :)
    This was happened only because of the Version problem of Report Builder with Oracle Applications.
    Reports Builder 10g is not compatiblie with Oracle Applications 11.5.10.
    Oracle 11.5+ will always expect the RDF from Reports 6i version. Because of this, the endocing was damaged.
    You can observe in the earlier post as encoding="&Endoding". Here +&Encoding should be replaced by some encoding mechanism like "UTF-8".+
    Finally corrected the version and got the Output as expected.
    Thanks !

  • Permission Denied error generating XML file

    We’re using ODI to write out files to a Windows CIFS file system through an agent installed on the ODI Unix server. In order to do this, we had to create the agent using a user ID that had permission to write to the Windows file system. For writing out flat files, this worked great; we have no problems at all.
    However, for writing out XML files to the file system, we’re getting an error that says Permission Denied. We do NOT get the error if we write the XML to a Unix directory, only if we attempt to write it to the CIFS file system. I have two questions:
    1.     Is ODI able to execute against a Windows CIFS file system from UNIX to generate XML files?
    2.     If so, is there a list of permissions required on the fileshare that the ODI needs to generate the XML?
    Below is the exact error we’re getting:
    0 : null : java.sql.SQLException: Could not save the file /mdm_conversion/TST/2.lsm because a class java.io.IOException occurred and said: Permission denied
    Has anyone ever performed something like this or encountered a similar problem?

    Hi,
    I found the issue and corrected it. :)
    This was happened only because of the Version problem of Report Builder with Oracle Applications.
    Reports Builder 10g is not compatiblie with Oracle Applications 11.5.10.
    Oracle 11.5+ will always expect the RDF from Reports 6i version. Because of this, the endocing was damaged.
    You can observe in the earlier post as encoding="&Endoding". Here +&Encoding should be replaced by some encoding mechanism like "UTF-8".+
    Finally corrected the version and got the Output as expected.
    Thanks !

Maybe you are looking for

  • "Bullets & Lists" in Text Options

    Hi, i format some text as "Header", format the text (bold, underline, 18px, and Aphabetic Bullets), see the "Update" button an update the textstyle. Next step i write a line,mark it and choose textstyle "Header" . Now its Bold and 18px and underlined

  • Receiver file adapter with attachments.

    Hi I would like to pass a file receiver an attachment from a proxy. I have seen bits and pieces with attachments. I have read that its similar to the mail adapter. In the module localejbs/AF_Modules/PayloadSwapBean  module configuration: Parameter Na

  • Invoice List, via EDI

    Hi, We are trying to create an IDOC for our INVOICE LIST,by using the function module IDOC_OUTPUT_INVOIC but is failling to popuplate IDOC segments with the line item data. The function module seem not ready to read the structure of INVOICE LIST, bec

  • Dba_scheduler_jobs for clearing the sys audit table

    Hi. can u please tell me how to purge a sys.aud$ table records once its reached more than once lakh ... these 1 lakh is the threshold and other more data will be peridiodically purged by automated dba_scheduler_jobs. My db is - 10g so i need to alway

  • How to cancel membership?

    I can't get a hold of anyone from this company to cancel and now my membership auto-renewed!