--- src/java/main/org/jaxen/jdom/DocumentNavigator.java.orig 2003-06-30 01:22:57.000000000 +0200 +++ src/java/main/org/jaxen/jdom/DocumentNavigator.java 2004-09-09 19:14:06.000000000 +0200 @@ -78,6 +78,7 @@ import org.jdom.Document; import org.jdom.Element; import org.jdom.Namespace; +import org.jdom.Parent; import org.jdom.ProcessingInstruction; import org.jdom.Text; import org.jdom.input.SAXBuilder; @@ -227,7 +228,11 @@ nsMap.put( ns.getPrefix(), new XPathNamespace(elem, ns) ); } - current = current.getParent(); + Parent p = current.getParent(); + if ( p instanceof Element ) + current = (Element) p; + else + current = null; } nsMap.put( "xml", new XPathNamespace(elem, Namespace.XML_NAMESPACE) ); @@ -454,11 +459,13 @@ } else if ( context instanceof Text ) { - element = ((Text)context).getParent(); + Parent p = ((Text)context).getParent(); + if ( p instanceof Element ) element = (Element) p; } else if ( context instanceof Attribute ) { - element = ((Attribute)context).getParent(); + Parent p = ((Attribute)context).getParent(); + if ( p instanceof Element ) element = (Element) p; } else if ( context instanceof XPathNamespace ) { @@ -466,11 +473,12 @@ } else if ( context instanceof Comment ) { - element = ((Comment)context).getParent(); + element = (Element)((Comment)context).getParent(); } else if ( context instanceof ProcessingInstruction ) { - element = ((ProcessingInstruction)context).getParent(); + Parent p = ((ProcessingInstruction)context).getParent(); + if ( p instanceof Element ) element = (Element) p; } if ( element != null )