How to create a nested XML file with Oracle 11g / DBMS_XMLGEN?

Sipler

New Member
I'm using Oracle 11g ( 11.1.0.7.0 ) and I have to create a XML File of a simple Query. I'm using this file in Forms 6, exactly the User want to be able to create the XML-File during press a button in the form, so I have an PL/SQL Package what create a CLOB File with the XML-Data on the Server and with Forms 6i I read this File line for line ( UTL_FILE.FOPEN to read it, UTL_FILE.GET_LINE for the lines ) and with TEXT_IO.PUT_LINE I write the File on the client computer.This works wonderfull, but I have a problem with the XML-File.Now it looks like this ( Values are examples! ):\[code\]<?xml version="1.0" encoding="ISO-8859-1" ?><ShoeShop> <Article> <Artnumber>12345</Artnumber> <Artdesc>Black Shoes</Artdesc> </Article> <Article> <Artnumber>12346</Artnumber> <Artdesc>White Shoes</Artdesc> </Article></ShoeShop>\[/code\]ok.I want to create an XML file that looks like this, but I don't know how! I'm new to SQL/PLSQL, I'm learning till 2 Months, before this I've used Progress 4GL. So in Progress I've called that what I want to do "nested", but I don't know how to realize it with SQL/PLSQL.Example for the XML-File how I want to get it:\[code\]<?xml version="1.0" encoding="ISO-8859-1" ?><ShoeShop> <Article=12345> <Artdesc>Black Shoes</Artdesc> </Article=12345> <Article=12346> <Artdesc>White Shoes</Artdesc> </Article=12346></ShoeShop>\[/code\]Code snippets for creating the XML-File how it looks like the first example:\[code\]PROCEDURE XML_TO_CLOB( pi_Query IN VARCHAR2, pi_ParentNode IN VARCHAR2, pi_ChildNode IN VARCHAR2 ) IS qryCtx DBMS_XMLGEN.ctxHandle; cResult CLOB;BEGIN-- Create new Context for the Query qryCtx := DBMS_XMLGEN.newContext( pi_Query );-- Set Parent and Child Node DBMS_XMLGEN.setRowSetTag( qryCtx, pi_ParentNode ); DBMS_XMLGEN.SetRowTag( qryCtx, pi_ChildNode );-- setNullHandling to show Tag also when the value is NULL DBMS_XMLGEN.setNullHandling( qryCtx, DBMS_XMLGEN.EMPTY_TAG );-- getXML in CLOB cResult := DBMS_XMLGEN.getXML( qryCtx );-- Put encoding to the "Header" cResult := REPLACE( cResult, '<?xml version="1.0"?>, '<?xml version="1.0" encoding="ISO-8859-1" ?>' );-- Close Context DBMS_XMLGEN.closeContext( qryCtx );-- Write the CLOB to a file on the server to work with the data in Forms 6i DBMS_XMSLPROCESSOR.CLOB2FILE( cResult, 'ExampleDir', 'Example.xml' );END;\[/code\]Thanks a lot,Sarah
 
Back
Top