Skip to Main Content

Database Software

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

how to search and replace only tag values in xml and not tag columns?

548016May 4 2012 — edited Jul 11 2012
Hi,

I am new to xml db and i have a scenario where i need to search and replace xml content. The search is based on a plain text and not on any column.

I have a table as follows:

ID VARCHAR2(32 BYTE),
MESSAGE_TYPE VARCHAR2(64 BYTE),
MESSAGE_CONTENT XMLTYPE,
REJECTED_REASON VARCHAR2(256 BYTE)

And Sample XML as:

<?xml version="1.0" encoding="US-ASCII"?>
<MessageEnvelope>
<Header>
<Partner>Renault</Partner>
<MessageType>Release</MessageType>
<PartnerMessageType>S74</PartnerMessageType>
<MessageTime>2001-12-17T09:30:47.0Z</MessageTime>
<LinkToRawMessage>String</LinkToRawMessage>
</Header>
<Body>
<Release>
<Addresses>
<DealerDestAddr>ABCD</DealerDestAddr>
<DestAddr>ABCD</DestAddr>
<NextDestAddr/>
<StartAddr/>
</Addresses>
<Assignment/>
<ClientStatus/>
<Dates/>
<HoldInfo>
<HoldCode>HoldTest</HoldCode>
</HoldInfo>
<Message/>
<Partner>
<OrderGiverCode>CMR00BCV</OrderGiverCode>
</Partner>
<ToDo/>
<Transport/>
<Vehicle>
<VIN>W0LGDM9A_Ran11115</VIN>
</Vehicle>
</Release>
</Body>
</MessageEnvelope>


I am executing the foll query:

UPDATE t_xml D SET D.MESSAGE_CONTENT = replace( D.MESSAGE_CONTENT, 'ABCD', 'Chennai' )
WHERE d.MESSAGE_CONTENT.existsNode('//*[*="ABCD"= 1;

This works fine and replaces both <DealerDestAddr>ABCD</DealerDestAddr> and <DestAddr>ABCD</DestAddr> tag values to Chennai. But the problem i face is if there is a node with tag name <ABCD> also gets modified to <Chennai>. Please help me to rectify this issue.

Regards,
Sprightee
This post has been answered by odie_63 on Jun 29 2012
Jump to Answer
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Aug 8 2012
Added on May 4 2012
32 comments
1,082 views