Friday, July 21, 2017

Getting XML including the xml TAG

Sometime we need to extract some inner xml from the bigger xml, while parsing it.
One simple approach is to use the some String util (such as Apache commons etc.) and call stringBetween finction, but then it does not give you the parent tag and then you add the prefix and suffix the start and end tag respectively.

Alternatively you can use a mix of XQuery(to search the exact xml node) and then apply LS Serializer to get the inner xml or the sub xml as String.

In the below example of note xml, lets say we have to extract <attachments> xml. So, we will first try to get the node and then use LS Serailzer to get attachments.

The first piece of code, is the input, the second is the output we are looking for. And, the third one is the actual code.

So, that's it. Happy chopping the xmls! :) ;)




Prototype

Prototype is another creation pattern. Intent:  - Intent is to create objects by cloning existing instance  - Specify the kinds of obj...