What is the correct way to handle object which is instance of class in apache.xerces?
- by Roman
Preface: I'm working on docx parser for java. docx format is based on xml. When I read document its parts are being unmarshalled (with JAXB). And I get a tree of certain elements based on xml markup.
Almost problem: But some elements (which are at very deep xml level) returned not as certain class from docx spec (i.e. CTStyle, CTDrawing, CTInline etc) but as Object. Those objects are indeed instances of xerces classes, e.g. ElementNSImpl.
Problem: How should I handle these objects. The simplest approach is:
CTGraphicData gData = getGraphicData ();
Object obj = gData.getAny().get(0);
ElementNSImpl element = (ElementNSImpl)obj;
But it doesn't seem to be a good solution. I've never worked with xerces directly. What is the better way to do this casting? (If anyone also give me a tip about right way to iterate through nodes it would be great).