xpath in java without reflection

MaisieN1968

New Member
I have to work a lot with JAXB objects and there is an annoying thing when getting a value. Let's suppose I have got the next XML:\[code\]...<a> <b> <c>1</c> </b></a>...\[/code\]In java I can reach the value of the element c as follows:\[code\]xml.getA().getB().getC()\[/code\]However if the elements are not mandatory then I have to implement many if conditions to check whether or not the element is null.\[code\]if (xml != null && xml.getA() != null && xml.getA().getB() != null && xml.getA().getB().getC() != null { ...}\[/code\]I would like to use XPath directly on the JAXB objects to avoid writing these horrible if conditions. I know there are some similar tools (e.g. Apache JXPAth) but usually these frameworks use reflection. I don't want to use reflection as it impacts the performance badly.Unfortunately I cannot imagine any solution without using reflection but perhaps there is one.Could you help me?Thanks,V.
 
Back
Top