FileDocCategorySizeDatePackage
documentimportnode20.javaAPI DocAndroid 1.5 API4936Wed May 06 22:41:04 BST 2009org.w3c.domts.level2.core

documentimportnode20

public final class documentimportnode20 extends org.w3c.domts.DOMTestCase
The importNode method imports a node from another document to this document. The returned node has no parent; (parentNode is null). The source node is not altered or removed from the original document but a new copy of the source node is created. Using the method importNode with deep=true, import a entity node ent4 from this document to a new document object. The replacement text of this entity is an element node, a cdata node and a pi. Verify if the nodes have been imported correctly by checking the nodeNames of the imported element node, the data for the cdata nodes and the PItarget and PIData for the pi nodes.
author
IBM
author
Neil Delima
see
http://www.w3.org/TR/DOM-Level-2-Core/core
see
http://www.w3.org/TR/DOM-Level-2-Core/core#Core-Document-importNode

Fields Summary
Constructors Summary
public documentimportnode20(org.w3c.domts.DOMTestDocumentBuilderFactory factory)
Constructor.

param
factory document factory, may not be null
throws
org.w3c.domts.DOMTestIncompatibleException Thrown if test is not compatible with parser configuration


      org.w3c.domts.DocumentBuilderSetting[] settings = 
          new org.w3c.domts.DocumentBuilderSetting[] {
org.w3c.domts.DocumentBuilderSetting.namespaceAware,
org.w3c.domts.DocumentBuilderSetting.notExpandEntityReferences
        };
        DOMTestDocumentBuilderFactory testFactory = factory.newInstance(settings);
        setFactory(testFactory);

    //
    //   check if loaded documents are supported for content type
    //
    String contentType = getContentType();
    preload(contentType, "staffNS", true);
    
Methods Summary
public java.lang.StringgetTargetURI()
Gets URI that identifies the test.

return
uri identifier of test

      return "http://www.w3.org/2001/DOM-Test-Suite/level2/core/documentimportnode20";
   
public static voidmain(java.lang.String[] args)
Runs this test from the command line.

param
args command line arguments

        DOMTestCase.doMain(documentimportnode20.class, args);
   
public voidrunTest()
Runs the test case.

throws
Throwable Any uncaught exception causes test to fail

      Document doc;
      Document docImp;
      DOMImplementation domImpl;
      DocumentType docType;
      DocumentType docTypeNull = null;

      NamedNodeMap nodeMap;
      Entity entity4;
      Entity entityImp4;
      Element element;
      CharacterData cdata;
      ProcessingInstruction pi;
      NodeList childList;
      NodeList elemchildList;
      String ent4Name;
      String ent4ImpName;
      String cdataVal;
      String piTargetVal;
      String piDataVal;
      doc = (Document) load("staffNS", true);
      domImpl = doc.getImplementation();
      docType = doc.getDoctype();
      docImp = domImpl.createDocument("http://www.w3.org/DOM/Test", "a:b", docTypeNull);
      nodeMap = docType.getEntities();
      entity4 = (Entity) nodeMap.getNamedItem("ent4");
      entityImp4 = (Entity) docImp.importNode(entity4, true);
      childList = entityImp4.getChildNodes();
      element = (Element) childList.item(0);
      elemchildList = element.getChildNodes();
      cdata = (CharacterData) elemchildList.item(0);
      pi = (ProcessingInstruction) childList.item(1);
      ent4Name = entity4.getNodeName();
      ent4ImpName = entityImp4.getNodeName();
      cdataVal = cdata.getData();
      piTargetVal = pi.getTarget();
      piDataVal = pi.getData();
      assertEquals("documentimportnode20_Ent4NodeName", ent4Name, ent4ImpName);
      assertEquals("documentimportnode20_Cdata", "Element data", cdataVal);
      assertEquals("documentimportnode20_PITarget", "PItarget", piTargetVal);
      assertEquals("documentimportnode20_PIData", "PIdata", piDataVal);