documentimportnode02public final class documentimportnode02 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=false, import the attribute, "emp:zone" of the
element node which is retreived by its elementId="CANADA", into the another document.
Check the parentNode, nodeName, nodeType and nodeValue of the imported node to
verify if it has been imported correctly. |
Constructors Summary |
---|
public documentimportnode02(org.w3c.domts.DOMTestDocumentBuilderFactory factory)Constructor.
org.w3c.domts.DocumentBuilderSetting[] settings =
new org.w3c.domts.DocumentBuilderSetting[] {
org.w3c.domts.DocumentBuilderSetting.namespaceAware
};
DOMTestDocumentBuilderFactory testFactory = factory.newInstance(settings);
setFactory(testFactory);
//
// check if loaded documents are supported for content type
//
String contentType = getContentType();
preload(contentType, "staffNS", true);
preload(contentType, "staff", true);
|
Methods Summary |
---|
public java.lang.String | getTargetURI()Gets URI that identifies the test.
return "http://www.w3.org/2001/DOM-Test-Suite/level2/core/documentimportnode02";
| public static void | main(java.lang.String[] args)Runs this test from the command line.
DOMTestCase.doMain(documentimportnode02.class, args);
| public void | runTest()Runs the test case.
Document doc;
Document docImported;
Element element;
Attr attr;
Node importedAttr;
String nodeName;
int nodeType;
String nodeValue;
NodeList addresses;
Node attrsParent;
doc = (Document) load("staffNS", true);
docImported = (Document) load("staff", true);
addresses = doc.getElementsByTagNameNS("http://www.nist.gov", "address");
element = (Element) addresses.item(1);
attr = element.getAttributeNodeNS("http://www.nist.gov", "zone");
importedAttr = docImported.importNode(attr, false);
nodeName = importedAttr.getNodeName();
nodeType = (int) importedAttr.getNodeType();
nodeValue = importedAttr.getNodeValue();
attrsParent = importedAttr.getParentNode();
assertNull("documentimportnode02_parentNull", attrsParent);
assertEquals("documentimportnode02_nodeName", "emp:zone", nodeName);
assertEquals("documentimportnode02_nodeType", 2, nodeType);
assertEquals("documentimportnode02_nodeValue", "CANADA", nodeValue);
|
|