Skip to content
Advertisement

Delete node when child have a certain value is found

I intend to remove a node whenever I find the unit_qty tag with the value equal to 0.0000. For example considering that the message below is called MESSAGE_DATA:

the purpose of message_data is to return the following:

I’ve already tried the following options:

I don’t know if I’m looking up the tag wrong but I’ve tried it with several formats and none of them work. for example this:

I appreciate all the help!

Advertisement

Answer

  1. You haven’t specified namespace, but your xml contains it, so oracle tried to find wrong elements. To search in all namespaces you can use *: as a namespace;
  2. If you want to delete whole node Receipt you should specify exactly Receipt and put all other filters into [], so, in short, we can put filter by child nodes into the filter. for example: $NEWXML//*:Receipt[./*:ReceiptDtl/*:unit_qty/text() eq $NAME] means that we want to delete all Receipt which contains at least one child node ReceiptDtl/unit_qty with a value = $NAME;

Full example with test data: DBFiddle

User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement