Re: Urgent XML DOM question in Oracle

From: Nicklas <nilun75_at_gmail.com>
Date: Thu, 12 Mar 2009 17:16:22 -0700 (PDT)
Message-ID: <8695f26d-bdeb-4bc8-95a9-5b95e065cad8_at_y13g2000yqn.googlegroups.com>



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 Received on Thu Mar 12 2009 - 19:16:22 CDT

Original text of this message