本文整理汇总了Java中org.w3c.dom.Document.getElementsByTagName方法的典型用法代码示例。如果您正苦于以下问题:Java Document.getElementsByTagName方法的具体用法?Java Document.getElementsByTagName怎么用?Java Document.getElementsByTagName使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.w3c.dom.Document
的用法示例。
在下文中一共展示了Document.getElementsByTagName方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testJobIdXML
import org.w3c.dom.Document; //导入方法依赖的package包/类
@Test
public void testJobIdXML() throws Exception {
WebResource r = resource();
Map<JobId, Job> jobsMap = appContext.getAllJobs();
for (JobId id : jobsMap.keySet()) {
String jobId = MRApps.toString(id);
ClientResponse response = r.path("ws").path("v1").path("mapreduce")
.path("jobs").path(jobId).accept(MediaType.APPLICATION_XML)
.get(ClientResponse.class);
assertEquals(MediaType.APPLICATION_XML_TYPE, response.getType());
String xml = response.getEntity(String.class);
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
DocumentBuilder db = dbf.newDocumentBuilder();
InputSource is = new InputSource();
is.setCharacterStream(new StringReader(xml));
Document dom = db.parse(is);
NodeList job = dom.getElementsByTagName("job");
verifyAMJobXML(job, appContext);
}
}
示例2: testWriteXml
import org.w3c.dom.Document; //导入方法依赖的package包/类
@Test
public void testWriteXml() throws Exception {
StringWriter sw = new StringWriter();
ConfServlet.writeResponse(getTestConf(), sw, "xml");
String xml = sw.toString();
DocumentBuilderFactory docBuilderFactory
= DocumentBuilderFactory.newInstance();
DocumentBuilder builder = docBuilderFactory.newDocumentBuilder();
Document doc = builder.parse(new InputSource(new StringReader(xml)));
NodeList nameNodes = doc.getElementsByTagName("name");
boolean foundSetting = false;
for (int i = 0; i < nameNodes.getLength(); i++) {
Node nameNode = nameNodes.item(i);
String key = nameNode.getTextContent();
System.err.println("xml key: " + key);
if (TEST_KEY.equals(key)) {
foundSetting = true;
Element propertyElem = (Element)nameNode.getParentNode();
String val = propertyElem.getElementsByTagName("value").item(0).getTextContent();
assertEquals(TEST_VAL, val);
}
}
assertTrue(foundSetting);
}
示例3: getVirtEnvName
import org.w3c.dom.Document; //导入方法依赖的package包/类
/**
* Private method to get the name of the virtual environment
* given in virtualenv tag of warhorn config file
*
* @param build Build
* @param workspace Jenkins job workspace
* @param listener Task listener
* @return virtEnvName Name of the Virtual Environment
* @throws ParserConfigurationException ParserConfigurationException
* @throws SAXException SAXException
* @throws IOException IOException
*/
private String getVirtEnvName(Run<?,?> build, FilePath workspace, TaskListener listener)
throws ParserConfigurationException, SAXException, IOException{
String absWarhornConfig = "";
if (configType.equals("configGit")){
absWarhornConfig = workspace.getRemote() + "/configRepo/" + gitConfigFile;
} else {
absWarhornConfig = workspace.getRemote() + "/warhorn_config.xml";
}
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
DocumentBuilder db = dbf.newDocumentBuilder();
Document document = db.parse(new File(absWarhornConfig));
NodeList veNodeList = document.getElementsByTagName("virtualenv");
String virtEnvName = "";
if(veNodeList.getLength() > 0){
Element element = (Element) veNodeList.item(0);
virtEnvName = element.getAttribute("name");
}
return virtEnvName;
}
示例4: testJobTaskCountersXML
import org.w3c.dom.Document; //导入方法依赖的package包/类
@Test
public void testJobTaskCountersXML() throws Exception {
WebResource r = resource();
Map<JobId, Job> jobsMap = appContext.getAllJobs();
for (JobId id : jobsMap.keySet()) {
String jobId = MRApps.toString(id);
for (Task task : jobsMap.get(id).getTasks().values()) {
String tid = MRApps.toString(task.getID());
ClientResponse response = r.path("ws").path("v1").path("mapreduce")
.path("jobs").path(jobId).path("tasks").path(tid).path("counters")
.accept(MediaType.APPLICATION_XML).get(ClientResponse.class);
assertEquals(MediaType.APPLICATION_XML_TYPE, response.getType());
String xml = response.getEntity(String.class);
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
DocumentBuilder db = dbf.newDocumentBuilder();
InputSource is = new InputSource();
is.setCharacterStream(new StringReader(xml));
Document dom = db.parse(is);
NodeList info = dom.getElementsByTagName("jobTaskCounters");
verifyAMTaskCountersXML(info, task);
}
}
}
示例5: testValidUpload_ExtModuleOnly
import org.w3c.dom.Document; //导入方法依赖的package包/类
public void testValidUpload_ExtModuleOnly() throws Exception
{
File zipFile = getResourceFile("validExtModule.zip");
PostRequest postRequest = buildMultipartPostRequest(zipFile);
AuthenticationUtil.setFullyAuthenticatedUser(NON_ADMIN_USER);
Response response = sendRequest(postRequest, 403);
AuthenticationUtil.setFullyAuthenticatedUser(CUSTOM_MODEL_ADMIN);
response = sendRequest(postRequest, 200);
JSONObject json = new JSONObject(new JSONTokener(response.getContentAsString()));
assertFalse(json.has("modelName"));
String extModule = json.getString("shareExtModule");
Document document = XMLUtil.parse(extModule);
NodeList nodes = document.getElementsByTagName("id");
assertEquals(1, nodes.getLength());
assertNotNull(nodes.item(0).getTextContent());
}
示例6: testTasksXML
import org.w3c.dom.Document; //导入方法依赖的package包/类
@Test
public void testTasksXML() throws JSONException, Exception {
WebResource r = resource();
Map<JobId, Job> jobsMap = appContext.getAllJobs();
for (JobId id : jobsMap.keySet()) {
String jobId = MRApps.toString(id);
ClientResponse response = r.path("ws").path("v1").path("mapreduce")
.path("jobs").path(jobId).path("tasks")
.accept(MediaType.APPLICATION_XML).get(ClientResponse.class);
assertEquals(MediaType.APPLICATION_XML_TYPE, response.getType());
String xml = response.getEntity(String.class);
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
DocumentBuilder db = dbf.newDocumentBuilder();
InputSource is = new InputSource();
is.setCharacterStream(new StringReader(xml));
Document dom = db.parse(is);
NodeList tasks = dom.getElementsByTagName("tasks");
assertEquals("incorrect number of elements", 1, tasks.getLength());
NodeList task = dom.getElementsByTagName("task");
verifyAMTaskXML(task, jobsMap.get(id));
}
}
示例7: verifyAppQueueXML
import org.w3c.dom.Document; //导入方法依赖的package包/类
protected static void
verifyAppQueueXML(ClientResponse response, String queue)
throws ParserConfigurationException, IOException, SAXException {
assertEquals(MediaType.APPLICATION_XML_TYPE, response.getType());
String xml = response.getEntity(String.class);
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
DocumentBuilder db = dbf.newDocumentBuilder();
InputSource is = new InputSource();
is.setCharacterStream(new StringReader(xml));
Document dom = db.parse(is);
NodeList nodes = dom.getElementsByTagName("appqueue");
assertEquals("incorrect number of elements", 1, nodes.getLength());
Element element = (Element) nodes.item(0);
String responseQueue = WebServicesTestUtils.getXmlString(element, "queue");
assertEquals(queue, responseQueue);
}
示例8: getExternalMappingsDocument
import org.w3c.dom.Document; //导入方法依赖的package包/类
private Document getExternalMappingsDocument(Document externalMappingsDocument) throws FileNotFoundException {
NodeList externalNodes = externalMappingsDocument
.getElementsByTagName(INCLUDE_EXTERNAL_MAPPING);
int externalNodesLen = externalNodes.getLength();
if (externalNodesLen > 0) {
for (int k = 0; k < externalNodesLen; k++) {
Node parent = externalNodes.item(0).getParentNode();
List<Node> nodes = createMappingNodes(parent);
int len = parent.getChildNodes().getLength();
removeChildNodes(parent, len);
addChildNodes(xmlDocument, parent, nodes);
}
}
return xmlDocument;
}
示例9: testAppsXMLMulti
import org.w3c.dom.Document; //导入方法依赖的package包/类
@Test
public void testAppsXMLMulti() throws JSONException, Exception {
rm.start();
MockNM amNodeManager = rm.registerNode("127.0.0.1:1234", 2048);
rm.submitApp(CONTAINER_MB, "testwordcount", "user1");
rm.submitApp(2048, "testwordcount2", "user1");
amNodeManager.nodeHeartbeat(true);
WebResource r = resource();
ClientResponse response = r.path("ws").path("v1").path("cluster")
.path("apps").accept(MediaType.APPLICATION_XML)
.get(ClientResponse.class);
assertEquals(MediaType.APPLICATION_XML_TYPE, response.getType());
String xml = response.getEntity(String.class);
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
DocumentBuilder db = dbf.newDocumentBuilder();
InputSource is = new InputSource();
is.setCharacterStream(new StringReader(xml));
Document dom = db.parse(is);
NodeList nodesApps = dom.getElementsByTagName("apps");
assertEquals("incorrect number of elements", 1, nodesApps.getLength());
NodeList nodes = dom.getElementsByTagName("app");
assertEquals("incorrect number of elements", 2, nodes.getLength());
rm.stop();
}
示例10: testImportNode
import org.w3c.dom.Document; //导入方法依赖的package包/类
@Test
public void testImportNode() throws Exception {
Document document = createDOMWithNS("Node02.xml");
Document otherDocument = createDOMWithNS("ElementSample01.xml");
NodeList otherNodeList = otherDocument.getElementsByTagName("body");
Node importedNode = otherNodeList.item(0);
Node clone = importedNode.cloneNode(true);
Node retNode = document.importNode(importedNode, true);
assertTrue(clone.isEqualNode(importedNode)); //verify importedNode is not changed
assertNotEquals(retNode, importedNode);
assertTrue(importedNode.isEqualNode(retNode));
retNode = document.importNode(importedNode, false);
assertTrue(clone.isEqualNode(importedNode)); //verify importedNode is not changed
assertEquals(retNode.getNodeName(), importedNode.getNodeName());
assertFalse(importedNode.isEqualNode(retNode));
}
示例11: testJobIdInvalidXML
import org.w3c.dom.Document; //导入方法依赖的package包/类
@Test
public void testJobIdInvalidXML() throws JSONException, Exception {
WebResource r = resource();
try {
r.path("ws").path("v1").path("history").path("mapreduce").path("jobs")
.path("job_foo").accept(MediaType.APPLICATION_XML)
.get(JSONObject.class);
fail("should have thrown exception on invalid uri");
} catch (UniformInterfaceException ue) {
ClientResponse response = ue.getResponse();
assertEquals(Status.NOT_FOUND, response.getClientResponseStatus());
assertEquals(MediaType.APPLICATION_XML_TYPE, response.getType());
String msg = response.getEntity(String.class);
System.out.println(msg);
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
DocumentBuilder db = dbf.newDocumentBuilder();
InputSource is = new InputSource();
is.setCharacterStream(new StringReader(msg));
Document dom = db.parse(is);
NodeList nodes = dom.getElementsByTagName("RemoteException");
Element element = (Element) nodes.item(0);
String message = WebServicesTestUtils.getXmlString(element, "message");
String type = WebServicesTestUtils.getXmlString(element, "exception");
String classname = WebServicesTestUtils.getXmlString(element,
"javaClassName");
verifyJobIdInvalid(message, type, classname);
}
}
示例12: getUserId
import org.w3c.dom.Document; //导入方法依赖的package包/类
private String getUserId(Document messageDoc) throws Exception {
NodeList nodes = messageDoc.getElementsByTagName("saml2:NameID");
if (nodes.getLength() == 0) {
throw new Exception("There is no userId");
}
return nodes.item(0).getTextContent();
}
示例13: verifySchedulerFifoXML
import org.w3c.dom.Document; //导入方法依赖的package包/类
public void verifySchedulerFifoXML(String xml) throws JSONException,
Exception {
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
DocumentBuilder db = dbf.newDocumentBuilder();
InputSource is = new InputSource();
is.setCharacterStream(new StringReader(xml));
Document dom = db.parse(is);
NodeList nodesSched = dom.getElementsByTagName("scheduler");
assertEquals("incorrect number of elements", 1, nodesSched.getLength());
NodeList nodes = dom.getElementsByTagName("schedulerInfo");
assertEquals("incorrect number of elements", 1, nodes.getLength());
for (int i = 0; i < nodes.getLength(); i++) {
Element element = (Element) nodes.item(i);
verifyClusterSchedulerFifoGeneric(
WebServicesTestUtils.getXmlAttrString(element, "xsi:type"),
WebServicesTestUtils.getXmlString(element, "qstate"),
WebServicesTestUtils.getXmlFloat(element, "capacity"),
WebServicesTestUtils.getXmlFloat(element, "usedCapacity"),
WebServicesTestUtils.getXmlInt(element, "minQueueMemoryCapacity"),
WebServicesTestUtils.getXmlInt(element, "maxQueueMemoryCapacity"),
WebServicesTestUtils.getXmlInt(element, "numNodes"),
WebServicesTestUtils.getXmlInt(element, "usedNodeCapacity"),
WebServicesTestUtils.getXmlInt(element, "availNodeCapacity"),
WebServicesTestUtils.getXmlInt(element, "totalNodeCapacity"),
WebServicesTestUtils.getXmlInt(element, "numContainers"));
}
}
示例14: registerServlets
import org.w3c.dom.Document; //导入方法依赖的package包/类
private void registerServlets( Document document ) throws SAXException {
Hashtable nameToClass = new Hashtable();
NodeList nl = document.getElementsByTagName( "servlet" );
for (int i = 0; i < nl.getLength(); i++) registerServletClass( nameToClass, (Element) nl.item( i ) );
nl = document.getElementsByTagName( "servlet-mapping" );
for (int i = 0; i < nl.getLength(); i++) registerServlet( nameToClass, (Element) nl.item( i ) );
}
示例15: registerFilters
import org.w3c.dom.Document; //导入方法依赖的package包/类
private void registerFilters( Document document ) throws SAXException {
Hashtable nameToClass = new Hashtable();
NodeList nl = document.getElementsByTagName( "filter" );
for (int i = 0; i < nl.getLength(); i++) registerFilterClass( nameToClass, (Element) nl.item( i ) );
nl = document.getElementsByTagName( "filter-mapping" );
for (int i = 0; i < nl.getLength(); i++) registerFilter( nameToClass, (Element) nl.item( i ) );
}