FileDocCategorySizeDatePackage
HasAttribute.javaAPI DocAndroid 1.5 API3896Wed May 06 22:41:06 BST 2009tests.org.w3c.dom

HasAttribute

public final class HasAttribute extends DOMTestCase
The "hasAttribute()" method for an Element should return true if the element has an attribute with the given name. Retrieve the first "address" element and the "hasAttribute()" method should return false since the element does not have a default value.
author
NIST
author
Mary Brady
see
http://www.w3.org/TR/DOM-Level-2-Core/core#ID-ElHasAttr

Fields Summary
DOMDocumentBuilderFactory
factory
DocumentBuilder
builder
Constructors Summary
Methods Summary
protected voidsetUp()

        super.setUp();
        try {
            factory = new DOMDocumentBuilderFactory(DOMDocumentBuilderFactory
                    .getConfiguration1());
            builder = factory.getBuilder();
        } catch (Exception e) {
            fail("Unexpected exception" + e.getMessage());
        }
    
protected voidtearDown()

        factory = null;
        builder = null;
        super.tearDown();
    
public voidtestHasAttribute1()
Runs the test case.

throws
Throwable Any uncaught exception causes test to fail

        Document doc;
        NodeList elementList;
        Element testNode;
        boolean state;
        doc = (Document) load("staff", builder);
        elementList = doc.getElementsByTagName("address");
        testNode = (Element) elementList.item(4);
        state = testNode.hasAttribute("domestic");
        assertFalse("throw_False", state);
    
public voidtestHasAttribute3()

        Document doc;
        NodeList elementList;
        Element testNode;
        boolean state;
        doc = (Document) load("staff", builder);
        elementList = doc.getElementsByTagName("address");
        testNode = (Element) elementList.item(0);
        state = testNode.hasAttribute("nomatch");
        assertFalse("throw_False", state);
    
public voidtestHasAttribute4()

        Document doc;
        NodeList elementList;
        Element testNode;
        boolean state;
        doc = (Document) load("staffNS", builder);
        elementList = doc.getElementsByTagName("address");
        testNode = (Element) elementList.item(0);
        state = testNode.hasAttribute("dmstc:domestic");
        assertTrue("hasDomesticAttr", state);