You are viewing a plain text version of this content. The canonical link for it is here.
Posted to j-dev@xerces.apache.org by br...@homepoint.com on 2000/10/04 16:38:05 UTC
Child Nodes/Elements
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