1 18 package org.apache.batik.dom; 19 20 import org.w3c.dom.*; 21 22 import java.io.*; 23 import java.net.*; 24 import org.apache.batik.dom.util.*; 25 import org.apache.batik.util.*; 26 import org.apache.batik.test.*; 27 28 34 public class GetElementsByTagNameNSTest extends AbstractTest { 35 protected String testFileName; 36 protected String rootTag; 37 protected String tagName; 38 39 public GetElementsByTagNameNSTest(String file, 40 String root, 41 String tag) { 42 testFileName = file; 43 rootTag = root; 44 tagName = tag; 45 } 46 47 public TestReport runImpl() throws Exception { 48 String parser = 49 XMLResourceDescriptor.getXMLParserClassName(); 50 51 DocumentFactory df 52 = new SAXDocumentFactory 53 (GenericDOMImplementation.getDOMImplementation(), parser); 54 55 File f = (new File(testFileName)); 56 URL url = f.toURL(); 57 Document doc = df.createDocument(null, 58 rootTag, 59 url.toString(), 60 url.openStream()); 61 62 Element root = doc.getDocumentElement(); 63 NodeList lst = root.getElementsByTagNameNS(null, tagName); 64 65 if (lst.getLength() != 1) { 66 DefaultTestReport report = new DefaultTestReport(this); 67 report.setErrorCode("error.getElementByTagNameNS.failed"); 68 report.setPassed(false); 69 return report; 70 } 71 72 Node n; 73 while ((n = root.getFirstChild()) != null) { 74 root.removeChild(n); 75 } 76 77 if (lst.getLength() != 0) { 78 DefaultTestReport report = new DefaultTestReport(this); 79 report.setErrorCode("error.getElementByTagNameNS.failed"); 80 report.setPassed(false); 81 return report; 82 } 83 84 return reportSuccess(); 85 } 86 87 } 88 | Popular Tags |