I'm trying to parse an XML for reading some special nodes. However one of the nodes has user comments which contain all types of special characters including &, <, >, & etc. Unfortunately I cannot edit the XML's.
While I am using REPLACE to remove some of them, the '<' and '>' is clashing with the node delimiters.
Any suggestions from experts here? Maybe some possible solutions. Please note I am a novice so detailed guidance will be appreciated.
- REPLACE all special characters including '<' and '>'
- Skip reading any special character
- Limit the data I read. The comment node comes quiet far down in the XML where as I just need the top of the XML CLOB. If there is a way to limit XMLPARSE to certain number of characters, that can work but its not an ideal solution
- Utilize another function instead of XMLPARSE.
Here's how my script looks like:
SELECT *
FROM TRANSACTION_DATA_TABLE tdt, trxData,
XMLTABLE
('$d/*:Request/*:AppData' PASSING XMLPARSE(DOCUMENT REPLACE(tdt.TRAN_DATA, '&', '') AS "d"
COLUMNS
FNAME CHAR(20) PATH '*:FirstName',
LNAME CHAR(20) PATH '*:LastName'
)
TIA.
It would really help to have DDL and DML provided so that the problem can be treated fully, but here is something that may assist. You might also add to the fiddle(s) as an addition to your question.
Here is a simple example of how to return wanted elements of XML and then strip some characters from them - for DB2:
DB2 fiddle
or. use regex_replace perhaps?
Oracle fiddle (as I wasn't sure which db this was for)