jnajayjain
asked on
updateXML function of Oracle XML DB - how to replace a node in xml stored in CLOB column of database.
Guys,
How can I replace a node (with some another) in xml which is stored in the CLOB column of a table.
I want to use the updateXML function such that, After updating the xml, it should return a new instance of XMLType.
heres the complete scenario.
table is -
create table TAB1
(
CONTENT_ID NUMBER(9),
XML_FILE CLOB
)
select * from tab1
CONTENT_ID XML_FILE
15000 <CLOB>
The XML_FILE column contains the below XML.
<document>
<document-metadata/>
<feature content-id="14850">asda</f eature>
<content-group content-id="14845"/>
<content-group>Content is within the document itself</content-group>
<content-group content-id="14847"/>
<content-group>Content is within the document itself</content-group>
</document>
Now I want to replace 3rd line of xml (below)
<feature content-id="14850">asda</f eature>
With
<feature content-id="14850" acl=”500900907,500900906” > This is a feature Content </feature>
So that I will get a new instance of XML look like -
<document>
<document-metadata/>
<feature content-id="14850" acl=”500900907,500900906” > This is a feature Content </feature>
<content-group content-id="14845"/>
<content-group>Content is within the document itself</content-group>
<content-group content-id="14847"/>
<content-group>Content is within the document itself</content-group>
</document>
I am trying the below query but it is not working.
SELECT UPDATEXML(XMLTYPE(xml_file ),'/docume nt/feature ', '<feature content-id="14850" acl=”500900907,500900906” > This is a feature Content </feature>').getstringval( )
FROM tab1
thanks in advance.
Ajay.
How can I replace a node (with some another) in xml which is stored in the CLOB column of a table.
I want to use the updateXML function such that, After updating the xml, it should return a new instance of XMLType.
heres the complete scenario.
table is -
create table TAB1
(
CONTENT_ID NUMBER(9),
XML_FILE CLOB
)
select * from tab1
CONTENT_ID XML_FILE
15000 <CLOB>
The XML_FILE column contains the below XML.
<document>
<document-metadata/>
<feature content-id="14850">asda</f
<content-group content-id="14845"/>
<content-group>Content is within the document itself</content-group>
<content-group content-id="14847"/>
<content-group>Content is within the document itself</content-group>
</document>
Now I want to replace 3rd line of xml (below)
<feature content-id="14850">asda</f
With
<feature content-id="14850" acl=”500900907,500900906” > This is a feature Content </feature>
So that I will get a new instance of XML look like -
<document>
<document-metadata/>
<feature content-id="14850" acl=”500900907,500900906” > This is a feature Content </feature>
<content-group content-id="14845"/>
<content-group>Content is within the document itself</content-group>
<content-group content-id="14847"/>
<content-group>Content is within the document itself</content-group>
</document>
I am trying the below query but it is not working.
SELECT UPDATEXML(XMLTYPE(xml_file
FROM tab1
thanks in advance.
Ajay.
ASKER
Hi slightwv,
I regret.
The output of your query is coming as below - Which is not helpful.
-------------------------- ---------- ---------- ----------
<document>
<document-metadata/>
<feature content-id="14850"><fea ture content-id="14850&quo t; acl=”500900907,500900906” > This is a feature Content </feature></feature>
<content-group content-id="14845"/>
<content-group>Content is within the document itself</content-group>
<content-group content-id="14847"/>
<content-group>Content is within the document itself</content-group>
</document>
-------------------------- ---------- ---------- ---------
Thanks,
Ajay.
I regret.
The output of your query is coming as below - Which is not helpful.
--------------------------
<document>
<document-metadata/>
<feature content-id="14850"><fea
<content-group content-id="14845"/>
<content-group>Content is within the document itself</content-group>
<content-group content-id="14847"/>
<content-group>Content is within the document itself</content-group>
</document>
--------------------------
Thanks,
Ajay.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
You can do this by,
update TAB1 set XML_FILE = sys.XMLTYPE.UPDATEXML(XML_ FILE, '/document/feature', '<feature content-id="14850" acl=”500900907,500900906” > This is a feature Content </feature>');
update TAB1 set XML_FILE = sys.XMLTYPE.UPDATEXML(XML_
ASKER
Yep It is working well now.
Thanks,
Ajay.
Thanks,
Ajay.
ASKER
Hi slightwv ,
Points for this is yours but could you pelase do a favour -
Can I store the below tag in a varchar2 field say
tempFeature varchar2(1000) = '<feature content-id="14850" acl=”500900907,500900906” > This is a feature Content </feature>' ;
and then use the updateXML such taht -
SELECT UPDATEXML(XMLTYPE(xml_file ),'/docume nt/feature ', 'valueOf(tempFeature)').ge tstringval ()
FROM tab1
where valueOF(tempfeature) replaces the string stored in it.
Thanks,
Ajay.
Points for this is yours but could you pelase do a favour -
Can I store the below tag in a varchar2 field say
tempFeature varchar2(1000) = '<feature content-id="14850" acl=”500900907,500900906” > This is a feature Content </feature>' ;
and then use the updateXML such taht -
SELECT UPDATEXML(XMLTYPE(xml_file
FROM tab1
where valueOF(tempfeature) replaces the string stored in it.
Thanks,
Ajay.
ASKER
CAN ANYONE PLEASE GIVE ME A QUICK HELP ON THIS ?
Thanks,
Ajay.
Thanks,
Ajay.
ASKER
Hey it was a silly question which I asked. answer is simple as below.
SELECT UPDATEXML(XMLTYPE(xml_file ),'/docume nt/feature ', tempFeature).getstringval( )
FROM tab1
Thanks,
Ajay.
SELECT UPDATEXML(XMLTYPE(xml_file
FROM tab1
Thanks,
Ajay.
Glad you found the answer. Sorry I could note get back to you on this. I was out of the office on Friday.
See if this is it (notice the addition of "text()"):
SELECT UPDATEXML(XMLTYPE(xml_file