Package org.dom4j

Examples of org.dom4j.XPath



          Document document;
          try {
            document = xmlReader.read(outputXml);
            XPath xpath = DocumentHelper.createXPath("//hibernate-mapping/class/set");
            List list = xpath.selectNodes(document);
            assertEquals("Expected to get one set element", 1, list.size());
            Element node = (Element) list.get(0);
            assertEquals(node.attribute( "table" ).getText(),"UserGroup");
            assertEquals(node.attribute( "name" ).getText(),"users");
            assertEquals(node.attribute( "inverse" ).getText(),"true");
View Full Code Here


        }
    }

    private XPath createXPath( String xpathExpr )
    {
        XPath xpath = document.createXPath( xpathExpr );
        if ( !this.namespaceMap.isEmpty() )
        {
            xpath.setNamespaceURIs( this.namespaceMap );
        }
        return xpath;
    }
View Full Code Here

    }

    public boolean hasElement( String xpathExpr )
        throws XMLException
    {
        XPath xpath = createXPath( xpathExpr );
        Object evaluated = xpath.selectSingleNode( document );

        if ( evaluated == null )
        {
            return false;
        }
View Full Code Here

    }

    public String getElementText( Node context, String xpathExpr )
        throws XMLException
    {
        XPath xpath = createXPath( xpathExpr );
        Object evaluated = xpath.selectSingleNode( context );

        if ( evaluated == null )
        {
            return null;
        }
View Full Code Here

    }

    public String getElementText( String xpathExpr )
        throws XMLException
    {
        XPath xpath = createXPath( xpathExpr );
        Object evaluated = xpath.selectSingleNode( document );

        if ( evaluated == null )
        {
            return null;
        }
View Full Code Here

    }

    public List getElementList( String xpathExpr )
        throws XMLException
    {
        XPath xpath = createXPath( xpathExpr );
        Object evaluated = xpath.evaluate( document );

        if ( evaluated == null )
        {
            return null;
        }
View Full Code Here

                xpathResult = dom4jDoc.valueOf(pattern);
            }
            else
            {
                // create an xpath expression with namespaces and evaluate it
                XPath xpath = DocumentHelper.createXPath(pattern);
                xpath.setNamespaceURIs(namespaces);
                xpathResult = xpath.valueOf(dom4jDoc);
            }
        }
        // Payload is a Java object
        else
        {
View Full Code Here

            Object result = null;
            if (src instanceof String)
            {
                Document doc = DocumentHelper.parseText((String) src);

                XPath xpath = doc.createXPath(expression);
                if (namespaces != null)
                {
                    xpath.setNamespaceURIs(namespaces);
                }

                // This is the way we always did it before, so keep doing it that way
                // as xpath.evaluate() will return non-string results (like Doubles)
                // for some scenarios.
                if (outputType == null && singleResult)
                {
                    return xpath.valueOf(doc);
                }

                // TODO handle non-list cases, see
                //http://www.dom4j.org/apidocs/org/dom4j/XPath.html#evaluate(java.lang.Object)
                Object obj = xpath.evaluate(doc);
                if (obj instanceof List)
                {
                    for (int i = 0; i < ((List<?>) obj).size(); i++)
                    {
                        final Node node = (Node) ((List<?>) obj).get(i);
View Full Code Here

            xpath_string = xpath_string + "/branch[@relURI='" + st.nextToken() + "']";
        }

        getLogger().debug("XPATH: " + xpath_string);

        XPath xpathSelector = DocumentHelper.createXPath(xpath_string);
        List nodes = xpathSelector.selectNodes(doc);

        if (nodes.isEmpty()) {
            getLogger().error(".act(): No nodes: " + xpath_string);
            getLogger().error(".act(): No child added!");
View Full Code Here

    }

    // Implementation methods
    // -------------------------------------------------------------------------
    protected void testXPath(Node node, String xpathText) {
        XPath xpath = node.createXPath(xpathText);
        Object object = xpath.evaluate(node);
    }
View Full Code Here

TOP

Related Classes of org.dom4j.XPath

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.