Re: Urgent XML DOM question in Oracle

From: Maxim Demenko <mdemenko_at_gmail.com>
Date: Fri, 13 Mar 2009 07:07:48 +0100
Message-ID: <49B9F834.70103_at_gmail.com>



Nicklas schrieb:
> On 13 Mar, 00:36, Maxim Demenko <mdeme..._at_gmail.com> wrote:
>> Nicklas schrieb:
>>
>>
>>
>>> Hi
>>> I have a question when I use the xmldom in a procedure.
>>> I need to have the following information in my file from the
>>> procedure:
>>> <?xml version="1.0" encoding="ISO-8859-1" ?>
>>>   <?POSTNET SND="XXXXX001" REC="XXXX0001" MSGTYPE="XXX"?>
>>> The problem with the xmldom is that I don't know how to add the tag
>>> <?
>>> POSTNET SND="XXXXX001" REC="XXXX0001" MSGTYPE="XXX"?>  to the root.
>>> Any suggestions would be very appreciated.
>>> Best regards
>>> Nicklas
>> Please, take into account, that subject URGENT is generally considered
>> on this newsgroup as rude. As well as multiposting - doing that you
>> don't increase your chance to get helpful answer, similarly by not
>> publishing your oracle version - especially xml functionality is subject
>> to change between releases.
>> But assuming, you are on 10gR2, you could do something like this with xmlpi.
>>
>> SQL> with t as (
>>    2  select xmltype('<?xml version="1.0" encoding="UTF-8" ?><doc/>') x
>> from dual
>>    3  )
>>    4  select updatexml(x,'/doc',
>>    5          xmlconcat(xmlpi(name "POSTNET",'SND="XXXXX001"
>> REC="XXXX0001" MSGTYPE="XXX"'),
>>    6          extract(x,'/doc'))
>>    7          ) xml
>>    8  from t;
>>
>> XML
>> ----------------------------------------------------------------------------------------------------
>> <?xml version="1.0" encoding="UTF-8"?><?POSTNET SND="XXXXX001"
>> REC="XXXX0001" MSGTYPE="XXX"?><doc/>
>>
>> If you are on 9i, there is no xmlpi, but you could search OTN XMLDB
>> Forum for workarounds (i have seen a couple, if i am not wrong).
>>
>> Best regards
>>
>> Maxim

>
> Thank you very much Maxim
>
> I did not know that the word Urgent was rude, then I appologise. The
> thing is that this has to be done tomorrow and I have no idea how to
> solve this.
> I am using xmldom in Oracle so the code you gave me I don't know if I
> can use.
>
> Here is the code I have now:
> declare
> document xmldom.DOMDocument; --The actual document
>
> --Nodes
> root_node xmldom.DOMNode; --The root node
> main_node xmldom.DOMNode; --The main node (Letters)
>
> --Elements
> root_elmt xmldom.DOMElement;
> BEGIN
>
> -- get document
> document := xmldom.newDOMDocument;
>
> -- create root node (Main)
> main_node := xmldom.makeNode(document);
>
> --Create the root element
> root_elmt := xmldom.createElement(document, 'Letters');
> -- xmldom.setAttribute(root_elmt, 'xmlns', 'http://www.akadia.com/xml/
> soug/xmldom');
> xmldom.setAttribute(root_elmt, 'xmlns:xsi', 'http://www.w3.org/2001/
> XMLSchema-instance');
> --Attach the root element
> root_node := xmldom.appendChild(main_node, xmldom.makeNode
> (root_elmt) );
>
>
> --THIS IS WHERE I WOULD LIKE TO ADD MY STRING: <?POSTNET
> SND="XXXXX001" REC="XXXX0001" MSGTYPE="XXX"?>
>
>
> xmldom.writeToFile(document,
> 'c:\temp\xml\docSample.xml',
> 'ISO-8859-1'
> );
>
> -- free resources
> xmldom.freeDocument(document);
>
> END;
> /
>
>
>
>
> Here is the result:
> <?xml version="1.0" encoding="ISO-8859-1"?>
> <Letters xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
>
> Best regards
> Nicklas

Did you looked at the docs?
http://download.oracle.com/docs/cd/B19306_01/appdev.102/b14258/d_xmldom.htm#i1121285

Here is an example of its usage
http://forums.oracle.com/forums/thread.jspa?messageID=1410040&#1410040

Best regards

Maxim Received on Fri Mar 13 2009 - 01:07:48 CDT

Original text of this message