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

CreateElementNS

public final class CreateElementNS extends DOMTestCase
The "createElementNS(namespaceURI,qualifiedName)" method for a Document should raise NAMESPACE_ERR DOMException if qualifiedName is malformed. Invoke method createElementNS(namespaceURI,qualifiedName) on the XMLNS Document with namespaceURI being the literal string "http://www.ecommerce.org/", and qualifiedName as "prefix::local". Method should raise NAMESPACE_ERR DOMException.
author
NIST
author
Mary Brady
see
http://www.w3.org/TR/DOM-Level-2-Core/core#xpointer(id('ID-258A00AF')/constant[@name='NAMESPACE_ERR'])
see
http://www.w3.org/TR/DOM-Level-2-Core/core#ID-DocCrElNS
see
http://www.w3.org/TR/DOM-Level-2-Core/core#xpointer(id('ID-DocCrElNS')/raises/exception[@name='DOMException']/descr/p[substring-before(.,':')='NAMESPACE_ERR'])

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 voidtestCreateElementNS1()
Runs the test case.

throws
Throwable Any uncaught exception causes test to fail

        String namespaceURI = "http://www.ecommerce.org/";
        String malformedName = "prefix::local";
        Document doc;
        
        doc = (Document) load("staffNS", builder);

        {
            boolean success = false;
            try {
                doc.createElementNS(namespaceURI, malformedName);
            } catch (DOMException ex) {
                success = (ex.code == DOMException.NAMESPACE_ERR);
            }
            assertTrue("throw_NAMESPACE_ERR", success);
        }
    
public voidtestCreateElementNS2()

        String namespaceURI = null;

        String qualifiedName = "prefix:local";
        Document doc;

        doc = (Document) load("staffNS", builder);

        {
            boolean success = false;
            try {
                doc.createElementNS(namespaceURI, qualifiedName);
            } catch (DOMException ex) {
                success = (ex.code == DOMException.NAMESPACE_ERR);
            }
            assertTrue("throw_NAMESPACE_ERR", success);
        }
    
public voidtestCreateElementNS3()

        String namespaceURI = "http://www.wedding.com/";
        String qualifiedName;
        Document doc;

        List<String> illegalQNames = new ArrayList<String>();
        illegalQNames.add("person:{");
        illegalQNames.add("person:}");
        illegalQNames.add("person:~");
        illegalQNames.add("person:'");
        illegalQNames.add("person:!");
        illegalQNames.add("person:@");
        illegalQNames.add("person:#");
        illegalQNames.add("person:$");
        illegalQNames.add("person:%");
        illegalQNames.add("person:^");
        illegalQNames.add("person:&");
        illegalQNames.add("person:*");
        illegalQNames.add("person:(");
        illegalQNames.add("person:)");
        illegalQNames.add("person:+");
        illegalQNames.add("person:=");
        illegalQNames.add("person:[");
        illegalQNames.add("person:]");
        illegalQNames.add("person:\\");
        illegalQNames.add("person:/");
        illegalQNames.add("person:;");
        illegalQNames.add("person:`");
        illegalQNames.add("person:<");
        illegalQNames.add("person:>");
        illegalQNames.add("person:,");
        illegalQNames.add("person:a ");
        illegalQNames.add("person:\"");

        doc = (Document) load("staffNS", builder);
        for (int indexN10098 = 0; indexN10098 < illegalQNames.size(); indexN10098++) {
            qualifiedName = (String) illegalQNames.get(indexN10098);

            {
                boolean success = false;
                try {
                    doc.createElementNS(namespaceURI, qualifiedName);
                } catch (DOMException ex) {
                    success = (ex.code == DOMException.INVALID_CHARACTER_ERR);
                }
                assertTrue("throw_INVALID_CHARACTER_ERR", success);
            }
        }
    
public voidtestCreateElementNS4()

        String namespaceURI = "http://www.w3.org/XML/1998/namespaces";
        String qualifiedName = "xml:element1";
        Document doc;

        doc = (Document) load("staffNS", builder);

        {
            boolean success = false;
            try {
                doc.createElementNS(namespaceURI, qualifiedName);
            } catch (DOMException ex) {
                success = (ex.code == DOMException.NAMESPACE_ERR);
            }
            assertTrue("throw_NAMESPACE_ERR", success);
        }
    
public voidtestCreateElementNS5()

        String namespaceURI = "http://www.nist.gov";
        String qualifiedName = "gov:faculty";
        Document doc;
        Element newElement;
        String elementName;
        doc = (Document) load("staffNS", builder);
        newElement = doc.createElementNS(namespaceURI, qualifiedName);
        elementName = newElement.getTagName();
        assertEquals("throw_Equals", qualifiedName, elementName);
    
public voidtestCreateElementNS6()

        String namespaceURI = "http://www.example.com/";

        Document doc;

        doc = (Document) load("hc_staff", builder);

        {
            boolean success = false;
            try {
                doc.createElementNS(namespaceURI, "");
            } catch (DOMException ex) {
                success = (ex.code == DOMException.NAMESPACE_ERR);
            }
            assertTrue("throw_NAMESPACE_ERR", success);
        }