Reputation: 23
I'm using Oracle 11g ( 11.1.0.7.0 ) and I have to create a XML File of a 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! ):
<?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>
ok. I want to create an XML file that looks like the following, 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:
<?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 snippet for creating the XML-File how it looks like the first example:
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;
Thanks a lot,
Sarah
Upvotes: 2
Views: 12478
Reputation: 146219
There are some examples of using DBMS_XMLGEN to generate nested documents in the documentation. Check out example 17-27.
The Oracle solution involves using user-defined types to specify the shape of the document, including columns which will be included as attributes rather than elements. This might be more infrastructure than you were expecting.
Upvotes: 1