Package nu.xom

Examples of nu.xom.XPathContext.addNamespace()


   
    public void testCantRebindXMLPrefix() {
       
        XPathContext context = new XPathContext();
        try {
            context.addNamespace("xml", "http://www.example.org");
            fail("Rebound xml prefix");
        }
        catch (NamespaceConflictException success) {
            assertNotNull(success.getMessage());
        }
View Full Code Here


    public void testCantBindNonPrefix() {
       
        XPathContext context = new XPathContext();
        try {
            context.addNamespace("foo:bar", "http://www.example.org");
            fail("Allowed preix with colon");
        }
        catch (IllegalNameException success) {
            assertNotNull(success.getMessage());
        }
View Full Code Here

        catch (IllegalNameException success) {
            assertNotNull(success.getMessage());
        }
       
        try {
            context.addNamespace("foo bar", "http://www.example.org");
            fail("Allowed preix with space");
        }
        catch (IllegalNameException success) {
            assertNotNull(success.getMessage());
        }
View Full Code Here

    }
   

    public void testLookupPrefix() {
        XPathContext context = new XPathContext();
        context.addNamespace("foo", "http://www.example.org");
        String url = context.lookup("foo");
        assertEquals("http://www.example.org", url);
    }
   
View Full Code Here

    }
   

    public void testLookupNonexistentPrefix() {
        XPathContext context = new XPathContext();
        context.addNamespace("foo", "http://www.example.org");
        String url = context.lookup("bar");
        assertNull(url);
    }
   
View Full Code Here

   
    public void testNamespaceQueryWithNullPrefix() {
       
        try {
            XPathContext context = new XPathContext("pre", "http://www.example.org");
            context.addNamespace(null, "http://www.w3.org");
            fail("Allowed null prefix");
        }
        catch (NullPointerException success) {
            assertNotNull(success.getMessage());
        }
View Full Code Here

   
    public void testNamespaceQueryWithEmptyPrefix() {
       
        try {
            XPathContext context = new XPathContext("pre", "http://www.example.org");
            context.addNamespace("", "http://www.w3.org");
        }
        catch (NamespaceConflictException success) {
            assertTrue(success.getMessage().length() > 1);
        }
       
View Full Code Here

       
        XPathContext context = new XPathContext("pre", "http://www.example.com");
        Nodes result = parent.query("child::pre:child", context);
        assertEquals(0, result.size());
       
        context.addNamespace("pre", "http://www.example.org");
        result = parent.query("child::pre:child", context);
        assertEquals(1, result.size());
        assertEquals(child, result.get(0));  
       
    }
View Full Code Here

        Attribute att = new Attribute("c:dog", "http://www.cafeconleche.org/", "test");
        parent.appendChild(child);
        child.addAttribute(att);
       
        XPathContext context = new XPathContext("pre", "http://www.example.org");
        context.addNamespace("c", "http://www.cafeconleche.org/");
        Nodes result = parent.query("child::pre:child", context);
        assertEquals(1, result.size());
        assertEquals(child, result.get(0));
       
        result = child.query("@c:*", context);
View Full Code Here

        XPathContext context = new XPathContext();
        for (int i = 0; i < contextElement.getNamespaceDeclarationCount(); i++) {
            String prefix = contextElement.getNamespacePrefix(i);
            if (! "".equals(prefix)) {
                context.addNamespace(prefix, contextElement.getNamespaceURI(prefix));
            }
        }
        return context;
    }
View Full Code Here

TOP
Copyright © 2018 www.massapi.com. 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.