Package org.jaxen.dom4j

Examples of org.jaxen.dom4j.Dom4jXPath


                HashMap<String, String> map = new HashMap<String, String>();
                map.put("pmh", "http://www.openarchives.org/OAI/2.0/")
                map.put("xb", "http://com/exlibris/digitool/repository/api/xmlbeans");
               
                try {
                  XPath xpathURL = new Dom4jXPath("/pmh:OAI-PMH/pmh:ListRecords/pmh:record/pmh:metadata/xb:digital_entity/pmh:urls/pmh:url[@type='stream']");
                  xpathURL.setNamespaceContext(new SimpleNamespaceContext(map));
           
            List urlList = xpathURL.selectNodes(list.getResponse());
            for (Object aNode : urlList) {
              try {
                if (aNode instanceof Node) {
                  resultList.add(new URI(((Node) aNode).getText()));
                }
View Full Code Here


        {
            SAXReader reader = new SAXReader();
           
            Document doc = reader.read( args[0] );
           
            XPath xpath = new Dom4jXPath( args[1] );
           
            List results = xpath.selectNodes( doc );

            Iterator resultIter = results.iterator();
           
            System.out.println("Document :: " + args[0] );
            System.out.println("   XPath :: " + args[1] );
View Full Code Here

   
    public static void main(String[] args) {
        try {
            URL u = new URL("http://www.ibiblio.org/xml/examples/shakespeare/much_ado.xml");
            Document doc = new SAXReader().read(u);
            Dom4jXPath xpath = new Dom4jXPath("PLAY/ACT/SCENE/SPEECH/SPEAKER");
           
            long start = System.currentTimeMillis();
           
            int count = 0;
            for (int i = 0; i < 1000; i++) {
                Element speaker = (Element) xpath.selectSingleNode(doc);
                count += (speaker == null ? 0 : 1);
            }
           
            long end = System.currentTimeMillis();
            System.out.println((end - start));
View Full Code Here

        }
    }
   
    public void testNullPointerException() throws JaxenException {
        Document doc = DocumentHelper.createDocument();
        XPath xpath = new Dom4jXPath("/foo");
        xpath.selectSingleNode(doc);
    }   
View Full Code Here

                            "" );
    }

    public void testConstruction() throws JaxenException
    {
        new Dom4jXPath( "/foo/bar/baz" );
    }
View Full Code Here

    }

    public void testSelection() throws JaxenException, DocumentException
    {

        XPath xpath = new Dom4jXPath( "/foo/bar/baz" );
        SAXReader reader = new SAXReader();
        Document doc = reader.read( BASIC_XML );
        List results = xpath.selectNodes( doc );
        assertEquals( 3, results.size() );
        Iterator iter = results.iterator();
        assertEquals( "baz",
                      ((Element)iter.next()).getName() );
        assertEquals( "baz",
View Full Code Here

    }
   
    public void testAsBoolean() throws JaxenException, DocumentException
    {
        XPath xpath = new Dom4jXPath( "/root/a = 'a'" );
        SAXReader reader = new SAXReader();
        Document doc = reader.read( "xml/simple.xml" );
        boolean answer = xpath.booleanValueOf( doc );
        assertTrue( "Xpath worked: " + xpath, answer );
        xpath = new Dom4jXPath( "'a' = 'b'" );
        answer = xpath.booleanValueOf( doc );
        assertTrue( "XPath should return false: " + xpath, ! answer );
    }
View Full Code Here

        Element element = new DefaultElement("test", ns1);
        Attribute attribute = new DefaultAttribute("pre:foo", "bar", ns2);
        element.add(attribute);
        Document doc = new DefaultDocument(element);
       
        XPath xpath = new Dom4jXPath( "//namespace::node()" );
        List results = xpath.selectNodes( doc );
        assertEquals( 3, results.size() );

    }
View Full Code Here

        String document = "<a xmlns:b=\"...\"/>";
        SAXReader reader = new SAXReader();
        Document doc = reader.read( new StringReader(document) );
       
        XPath xpath = new Dom4jXPath( "/a/b" );
        List results = xpath.selectNodes( doc );
        assertEquals( 0, results.size() );

    }
View Full Code Here

            element.add(attribute);
            Element root = new DefaultElement("root", ns0);
            root.add(element);
            Document doc = new DefaultDocument(root);
           
            XPath xpath = new Dom4jXPath( "/*/*/namespace::node()" );

            List results = xpath.selectNodes( doc );

            assertEquals( 4,
                          results.size() );
    }
View Full Code Here

TOP

Related Classes of org.jaxen.dom4j.Dom4jXPath

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.