XPathReader reader = new XPathReader("FileName.xml"); // To get a xml attribute. String expression = "/Main/Port/output/@code"; System.out.println(reader.read(expression,XPathConstants.STRING) + "n");
/** * Validation Xpath query * * @param query xpath query * @return true if xpath query valid */ public boolean isValidXpathQuery(String query) { try { XPathReader reader = new XPathReader(); reader.parse(query); } catch (Exception e) { return false; } return true; }
/** * Validation Xpath query * * @param query xpath query * @return true if xpath query valid */ public boolean isValidXpathQuery(String query) { try { XPathReader reader = new XPathReader(); reader.parse(query); } catch (Exception e) { return false; } return true; }
/** * @param args String[] * @throws SAXPathException */ public static void main(String[] args) throws SAXPathException { XPathReader reader = new XPathReader(); reader.setXPathHandler(new DebugXPathHandler()); reader .parse("/ns:one[@woof='dog']/two/./../two[functionTest(@a, @b, $woof:woof)]/three/*/four//*/five/six[@exists1 and @exists2]"); }
/** * @param args String[] * @throws SAXPathException */ public static void main(String[] args) throws SAXPathException { XPathReader reader = new XPathReader(); reader.setXPathHandler(new DebugXPathHandler()); reader .parse("/ns:one[@woof='dog']/two/./../two[functionTest(@a, @b, $woof:woof)]/three/*/four//*/five/six[@exists1 and @exists2]"); }
static Query getPathQuery(String path) throws SAXPathException { ApplicationContext ac = ApplicationContextHelper.getApplicationContext(); XPathReader reader = new XPathReader(); LuceneXPathHandler handler = new LuceneXPathHandler(); handler.setNamespacePrefixResolver((NamespaceService) ac.getBean("namespaceService")); handler.setDictionaryService((DictionaryService) ac.getBean("dictionaryService")); reader.setXPathHandler(handler); reader.parse(path); PathQuery pathQuery = handler.getQuery(); pathQuery.setRepeats(false); return pathQuery; }
static Query getPathQuery(String path) throws SAXPathException { ApplicationContext ac = ApplicationContextHelper.getApplicationContext(); XPathReader reader = new XPathReader(); LuceneXPathHandler handler = new LuceneXPathHandler(); handler.setNamespacePrefixResolver((NamespaceService) ac.getBean("namespaceService")); handler.setDictionaryService((DictionaryService) ac.getBean("dictionaryService")); reader.setXPathHandler(handler); reader.parse(path); PathQuery pathQuery = handler.getQuery(); pathQuery.setRepeats(false); return pathQuery; }
static @NonNull JaxenXPath create(final @NonNull Converter<String, QNameModule> converter, final @NonNull SchemaPath schemaPath, final @NonNull String xpath) throws JaxenException { final @NonNull Expr parsed; try { final XPathReader reader = new org.jaxen.saxpath.base.XPathReader(); final JaxenHandler handler = new JaxenHandler(); reader.setXPathHandler(handler); reader.parse(xpath); parsed = handler.getXPathExpr().getRootExpr(); } catch (org.jaxen.saxpath.XPathSyntaxException e) { throw new XPathSyntaxException(e); } catch (SAXPathException e) { throw new JaxenException(e); } LOG.debug("Compiled {} to expression {}", xpath, parsed); new ExprWalker(new ExprListener() { // FIXME: perform expression introspection to understand things like apex, etc. }).walk(parsed); return new JaxenXPath(converter, schemaPath, parsed); }
static @NonNull JaxenXPath create(final @NonNull Converter<String, QNameModule> converter, final @NonNull SchemaPath schemaPath, final @NonNull String xpath) throws JaxenException { final @NonNull Expr parsed; try { final XPathReader reader = new org.jaxen.saxpath.base.XPathReader(); final JaxenHandler handler = new JaxenHandler(); reader.setXPathHandler(handler); reader.parse(xpath); parsed = handler.getXPathExpr().getRootExpr(); } catch (org.jaxen.saxpath.XPathSyntaxException e) { throw new XPathSyntaxException(e); } catch (SAXPathException e) { throw new JaxenException(e); } LOG.debug("Compiled {} to expression {}", xpath, parsed); new ExprWalker(new ExprListener() { // FIXME: perform expression introspection to understand things like apex, etc. }).walk(parsed); return new JaxenXPath(converter, schemaPath, parsed); }