xerces-j-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From brent.john...@homepoint.com
Subject Child Nodes/Elements
Date Wed, 04 Oct 2000 14:38:05 GMT
I'm scanning XML documents as they come through looking for specific tags.
But, I get the following error when I try to read the tag name for a child
element:
java.lang.ClassCastException: org.apache.xerces.dom.TextImpl

Here is an example of what the instance doc looks like:
<txEvent>
    <PartyAlignment>
        ....
    </PartyAlignment>
</txEvent>
<txEvent>
    <Order>
        ....
    </Order>
</txEvent>
<txEvent>
    <Order>
        ...
    </Order>
</txEvent>

Here is the code that's causing it:
NodeList nodes = xmldoc.getElementsByTagName("txEvent");
int nsize = nodes.getLength();
String message = "";
for(int i = 0; i < nsize; i++) {
    Element txevent = (Element) nodes.item(i);
    if (txevent.hasChildNodes()) {
        Element child = (Element) txevent.getFirstChild(); //
<------------- Casting getFirstChild() is failing
        message += "Element: " + child.getTagName() + "\n";
    }
}
reply.generateContent(XMLReply.REPLY_WRN_DEBUG, message + "Total txEvents
Matched: " + totalEvents);

The "txEvent" tags are defined as being elementOnly in the schema - but it
appears as though the first child returned is some text information or
something else?

Any ideas?  Thanks,

- Brent


Mime
View raw message