XPathUtils { public static List<QName> extractQNames( XPath xpath ) { List<QName> list = new ArrayList<QName>(); try { Expr expr = new BaseXPath( xpath.getXPath(), null ).getRootExpr(); if ( expr instanceof LocationPath ) { LocationPath lp = (LocationPath) expr; for ( Object o : lp.getSteps() ) { findQName( list, (Step) o, xpath.getNamespaceContext() ); } } } catch ( JaxenException e ) { } return list; }  static List<QName> extractQNames( XPath xpath ); static Set<String> extractPrefixes( String text ); static Set<String> extractPrefixes( Expr xpath );  }
@Test public void testFindQNames() { NamespaceBindings ns = new NamespaceBindings(); ns.addNamespace( "app", "http: XPath path = new XPath( "/app:eins/app:zwei/app:drei/app:vier", ns ); QName q3 = new QName( "http: Assert.assertEquals( q3, XPathUtils.extractQNames( path ).get( 2 ) ); }