What is the correct way to handle object which is instance of class in apache.xerces?

Posted by Roman on Stack Overflow See other posts from Stack Overflow or by Roman
Published on 2010-03-23T15:11:39Z Indexed on 2010/03/23 15:13 UTC
Read the original article Hit count: 362

Filed under:
|

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).

© Stack Overflow or respective owner

Related posts about java

Related posts about xerces