I have an large list of XML documents stored in MySQL (yes I know…) and I’m wondering if there is an easy way to do a search and replace on the documents using just SQL.
In the example below, I’m trying to replace mandown (both the value & the element) with emergkey.
Original:
<clouddata>
<type>mandown</type>
<devicedata>
<nomotion>0</nomotion>
<mandown>1</mandown>
</devicedata>
</clouddata>
Desired:
<clouddata>
<type>emergkey</type>
<devicedata>
<nomotion>0</nomotion>
<emergykey>1</emergkey>
</devicedata>
</clouddata>
Note that I’ve simplified these examples and the real data is of various length and the elements are not necessarily ordered all the same.
The brain-dead method is
or in slightly safer fashion:
A truly safe method would be to pull each record into DOM and do the operations there, though this’d be slow on a large table.