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

ElementHasAttribute

public final class ElementHasAttribute extends DOMTestCase
The method hasAttribute returns true when an attribute with a given name is specified on this element or has a default value, false otherwise Invoke the hasAttribute method to check if the documentElement has attributres.
author
IBM
author
Neil Delima
see
http://www.w3.org/TR/DOM-Level-2-Core/core#ID-NodeHasAttrs

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;
        Element element;
        boolean state;
        doc = (Document) load("staff", builder);
        element = doc.getDocumentElement();
        state = element.hasAttribute("");
        assertFalse("elementhasattribute01", state);
    
public voidtestHasAttribute3()

        Document doc;
        Element element;
        boolean state;
        Attr attribute;
        
        doc = (Document) load("staff", builder);
        element = doc.createElement("address");
        attribute = doc.createAttribute("domestic");
        state = element.hasAttribute("domestic");
        assertFalse("elementhasattribute03_False", state);
        element.setAttributeNode(attribute);
        state = element.hasAttribute("domestic");
        assertTrue("elementhasattribute03_True", state);
    
public voidtestHasAttribute4()

        Document doc;
        Element element;
        boolean state;
        Attr attribute;
        
        doc = (Document) load("staff", builder);
        element = doc.createElement("address");
        attribute = doc.createAttribute("domestic");
        element.setAttributeNode(attribute);
        state = element.hasAttribute("domestic");
        assertTrue("elementhasattribute04", state);