Re: Urgent XML DOM question in Oracle
From: Nicklas <nilun75_at_gmail.com>
Date: Fri, 13 Mar 2009 02:32:53 -0700 (PDT)
Message-ID: <07d12a04-71e3-403f-a2c3-36397c577649_at_w35g2000yqm.googlegroups.com>
On 13 Mar, 07:07, Maxim Demenko <mdeme..._at_gmail.com> wrote:
> 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_xmld...
>
> Here is an example of its usagehttp://forums.oracle.com/forums/thread.jspa?messageID=1410040�
>
> Best regards
>
> Maxim
Date: Fri, 13 Mar 2009 02:32:53 -0700 (PDT)
Message-ID: <07d12a04-71e3-403f-a2c3-36397c577649_at_w35g2000yqm.googlegroups.com>
On 13 Mar, 07:07, Maxim Demenko <mdeme..._at_gmail.com> wrote:
> 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_xmld...
>
> Here is an example of its usagehttp://forums.oracle.com/forums/thread.jspa?messageID=1410040�
>
> Best regards
>
> Maxim
Thanks once again Maxim
Programing at 1 am is not a good idea, docs become a bit blurry at
that time :)
Thank you for your help, I got it now.
/Nicklas Received on Fri Mar 13 2009 - 04:32:53 CDT