org.w3c.dom.Element.getNodeName()方法的使用及代码示例

x33g5p2x  于2022-01-18 转载在 其他  
字(11.9k)|赞(0)|评价(0)|浏览(350)

本文整理了Java中org.w3c.dom.Element.getNodeName()方法的一些代码示例,展示了Element.getNodeName()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Element.getNodeName()方法的具体详情如下:
包路径:org.w3c.dom.Element
类名称:Element
方法名:getNodeName

Element.getNodeName介绍

暂无

代码示例

代码示例来源:origin: org.netbeans.api/org-openide-filesystems

private org.w3c.dom.Element find(org.w3c.dom.Element parent, String name, String kindRx) {
  NodeList nl = parent.getChildNodes();
  for (int i = 0; i < nl.getLength(); i++) {
    Node item = nl.item(i);
    if (item.getNodeType() != Node.ELEMENT_NODE) {
      continue;
    }
    org.w3c.dom.Element e = (org.w3c.dom.Element) item;
    if (e.getAttribute("name").equals(name) && e.getNodeName().matches(kindRx)) {
      return e;
    }
  }
  return null;
}

代码示例来源:origin: looly/hutool

/**
 * XML节点转换为Map
 *
 * @param node XML节点
 * @param result 结果Map类型
 * @return XML数据转换后的Map
 * @since 4.0.8
 */
public static Map<String, Object> xmlToMap(Node node, Map<String, Object> result) {
  if (null == result) {
    result = new HashMap<>();
  }
  final NodeList nodeList = node.getChildNodes();
  final int length = nodeList.getLength();
  Node childNode;
  Element childEle;
  for (int i = 0; i < length; ++i) {
    childNode = nodeList.item(i);
    if (isElement(childNode)) {
      childEle = (Element) childNode;
      result.put(childEle.getNodeName(), childEle.getTextContent());
    }
  }
  return result;
}

代码示例来源:origin: jeremylong/DependencyCheck

if (!"status".equals(doc.getDocumentElement().getNodeName())) {
  LOGGER.warn("Expected root node name of status, got {}", doc.getDocumentElement().getNodeName());
  return false;

代码示例来源:origin: geoserver/geoserver

public void testEncode() throws Exception {
    Ows10Factory f = Ows10Factory.eINSTANCE;
    GetCapabilitiesType caps = f.createGetCapabilitiesType();
    AcceptVersionsType versions = f.createAcceptVersionsType();
    caps.setAcceptVersions(versions);

    versions.getVersion().add("1.0.0");
    versions.getVersion().add("1.1.0");

    ByteArrayOutputStream output = new ByteArrayOutputStream();
    response.write(caps, output, null);

    Document d = DocumentBuilderFactory.newInstance().newDocumentBuilder().newDocument();
    TransformerFactory.newInstance()
        .newTransformer()
        .transform(
            new StreamSource(new ByteArrayInputStream(output.toByteArray())),
            new DOMResult(d));

    assertEquals("ows:GetCapabilities", d.getDocumentElement().getNodeName());
    assertEquals(2, d.getElementsByTagName("ows:Version").getLength());
  }
}

代码示例来源:origin: geoserver/geoserver

private void testSerializationWithMode(Mode mode) throws Exception {
  Catalog catalog = new CatalogImpl();
  CatalogFactory cFactory = catalog.getFactory();
  LayerGroupInfo group1 = cFactory.createLayerGroup();
  group1.setName("foo");
  group1.setTitle("foo title");
  group1.setAbstract("foo abstract");
  group1.setMode(mode);
  ByteArrayOutputStream out = out();
  persister.save(group1, out);
  // print(in(out));
  ByteArrayInputStream in = in(out);
  LayerGroupInfo group2 = persister.load(in, LayerGroupInfo.class);
  assertEquals(group1.getName(), group2.getName());
  assertEquals(group1.getTitle(), group2.getTitle());
  assertEquals(group1.getAbstract(), group2.getAbstract());
  assertEquals(group1.getMode(), group2.getMode());
  Document dom = dom(in(out));
  assertEquals("layerGroup", dom.getDocumentElement().getNodeName());
}

代码示例来源:origin: kiegroup/jbpm

public void executeWorkItem(WorkItem workItem,
    WorkItemManager mgr) {
  assertEquals("foo", ((Element) workItem
      .getParameter("Comment")).getNodeName());
  // assertEquals("mynode", ((Element)
  // workItem.getParameter("Comment")).getFirstChild().getNodeName());
  // assertEquals("user", ((Element)
  // workItem.getParameter("Comment")).getFirstChild().getFirstChild().getNodeName());
  // assertEquals("hello world", ((Element)
  // workItem.getParameter("coId")).getFirstChild().getFirstChild().getAttributes().getNamedItem("hello").getNodeValue());
}

代码示例来源:origin: apache/nifi

public static List<Element> getChildElementsByTagName(final Element element, final String tagName) {
  final List<Element> matches = new ArrayList<>();
  final NodeList nodeList = element.getChildNodes();
  for (int i = 0; i < nodeList.getLength(); i++) {
    final Node node = nodeList.item(i);
    if (!(node instanceof Element)) {
      continue;
    }
    final Element child = (Element) nodeList.item(i);
    if (child.getNodeName().equals(tagName)) {
      matches.add(child);
    }
  }
  return matches;
}

代码示例来源:origin: geotools/geotools

public void testEncodeComparison() throws Exception {
  Document doc = encode(FilterMockData.propertyIsEqualTo(), OGC.Filter);
  assertEquals("ogc:Filter", doc.getDocumentElement().getNodeName());
  assertEquals(1, doc.getElementsByTagNameNS(OGC.NAMESPACE, "PropertyIsEqualTo").getLength());
}

代码示例来源:origin: kiegroup/jbpm

public void executeWorkItem(WorkItem workItem,
    WorkItemManager mgr) {
  Object coIdParamObj = workItem.getParameter("coId");
  assertEquals("mydoc", ((Element) coIdParamObj).getNodeName());
  assertEquals("mynode", ((Element) workItem.getParameter("coId")).getFirstChild().getNodeName());
  assertEquals("user",
      ((Element) workItem.getParameter("coId"))
          .getFirstChild().getFirstChild()
          .getNodeName());
  assertEquals("hello world",
      ((Element) workItem.getParameter("coId"))
          .getFirstChild().getFirstChild()
          .getAttributes().getNamedItem("hello")
          .getNodeValue());
}

代码示例来源:origin: looly/hutool

/**
 * XML节点转换为Map
 *
 * @param node XML节点
 * @param result 结果Map类型
 * @return XML数据转换后的Map
 * @since 4.0.8
 */
public static Map<String, Object> xmlToMap(Node node, Map<String, Object> result) {
  if (null == result) {
    result = new HashMap<>();
  }
  final NodeList nodeList = node.getChildNodes();
  final int length = nodeList.getLength();
  Node childNode;
  Element childEle;
  for (int i = 0; i < length; ++i) {
    childNode = nodeList.item(i);
    if (isElement(childNode)) {
      childEle = (Element) childNode;
      result.put(childEle.getNodeName(), childEle.getTextContent());
    }
  }
  return result;
}

代码示例来源:origin: geoserver/geoserver

public void testHandleServiceException() throws Exception {
  ServiceException exception = new ServiceException("hello service exception");
  exception.setCode("helloCode");
  exception.setLocator("helloLocator");
  exception.getExceptionText().add("helloText");
  handler.handleServiceException(exception, requestInfo);
  InputStream input = new ByteArrayInputStream(response.getContentAsString().getBytes());
  DocumentBuilderFactory docBuilderFactory = DocumentBuilderFactory.newInstance();
  docBuilderFactory.setNamespaceAware(true);
  Document doc = docBuilderFactory.newDocumentBuilder().parse(input);
  assertEquals("ows:ExceptionReport", doc.getDocumentElement().getNodeName());
}

代码示例来源:origin: apache/nifi

private static List<Element> getChildrenByTagName(final Element element, final String tagName) {
  final List<Element> matches = new ArrayList<>();
  final NodeList nodeList = element.getChildNodes();
  for (int i = 0; i < nodeList.getLength(); i++) {
    final Node node = nodeList.item(i);
    if (!(node instanceof Element)) {
      continue;
    }
    final Element child = (Element) nodeList.item(i);
    if (child.getNodeName().equals(tagName)) {
      matches.add(child);
    }
  }
  return matches;
}

代码示例来源:origin: geotools/geotools

public void testEncodeLogical() throws Exception {
    Document doc = encode(FilterMockData.and(), OGC.Filter);

    assertEquals("ogc:Filter", doc.getDocumentElement().getNodeName());
    assertEquals(1, doc.getElementsByTagNameNS(OGC.NAMESPACE, "And").getLength());

    doc = encode(FilterMockData.not(), OGC.Filter);

    assertEquals("ogc:Filter", doc.getDocumentElement().getNodeName());
    assertEquals(1, doc.getElementsByTagNameNS(OGC.NAMESPACE, "Not").getLength());
  }
}

代码示例来源:origin: apache/geode

/**
 * <!ELEMENT type (description?, (stat)+)> <!ATTLIST type name CDATA #REQUIRED>
 */
private StatisticsType extractType(Element typeNode, StatisticsTypeFactory statFactory) {
 Assert.assertTrue(typeNode.getTagName().equals("type"));
 Assert.assertTrue(typeNode.hasAttribute("name"));
 final String typeName = typeNode.getAttribute("name");
 ArrayList stats = new ArrayList();
 NodeList statNodes = typeNode.getElementsByTagName("stat");
 for (int i = 0; i < statNodes.getLength(); i++) {
  Element statNode = (Element) statNodes.item(i);
  stats.add(extractStat(statNode, statFactory));
 }
 StatisticDescriptor[] descriptors =
   (StatisticDescriptor[]) stats.toArray(new StatisticDescriptor[stats.size()]);
 String description = "";
 {
  NodeList descriptionNodes = typeNode.getElementsByTagName("description");
  if (descriptionNodes.getLength() > 0) {
   // descriptionNodes will contain the both our description, if it exists,
   // and any nested stat descriptions. Ours will always be first
   Element descriptionNode = (Element) descriptionNodes.item(0);
   // but make sure the first one belongs to our node
   if (descriptionNode.getParentNode().getNodeName().equals(typeNode.getNodeName())) {
    description = extractDescription(descriptionNode);
   }
  }
 }
 return statFactory.createType(typeName, description, descriptors);
}

代码示例来源:origin: geoserver/geoserver

public void testErrorThrowingResponse() throws Exception {
    URL url = getClass().getResource("applicationContext-errorResponse.xml");

    try (FileSystemXmlApplicationContext context =
        new FileSystemXmlApplicationContext(url.toString())) {
      Dispatcher dispatcher = (Dispatcher) context.getBean("dispatcher");
      MockHttpServletRequest request = setupRequest();
      MockHttpServletResponse response = new MockHttpServletResponse();
      dispatcher.handleRequest(request, response);
      // the output is not there
      final String outputContent = response.getContentAsString();
      assertThat(outputContent, not(containsString("Hello world!")));
      // only the exception
      Document dom = XMLUnit.buildTestDocument(outputContent);
      assertEquals("ows:ExceptionReport", dom.getDocumentElement().getNodeName());
    }
  }
}

代码示例来源:origin: apache/nifi

public static List<Element> getChildElementsByTagName(final Element element, final String tagName) {
  final List<Element> matches = new ArrayList<>();
  final NodeList nodeList = element.getChildNodes();
  for (int i = 0; i < nodeList.getLength(); i++) {
    final Node node = nodeList.item(i);
    if (!(node instanceof Element)) {
      continue;
    }
    final Element child = (Element) nodeList.item(i);
    if (child.getNodeName().equals(tagName)) {
      matches.add(child);
    }
  }
  return matches;
}

代码示例来源:origin: geotools/geotools

public void testEncodeSpatial() throws Exception {
  Document doc = encode(FilterMockData.intersects(), OGC.Filter);
  assertEquals("ogc:Filter", doc.getDocumentElement().getNodeName());
  assertEquals(1, doc.getElementsByTagNameNS(OGC.NAMESPACE, "Intersects").getLength());
}

代码示例来源:origin: TeamNewPipe/NewPipe

private static NodeList selectNodes(Document xml, String[] path, String namespaceUri) throws XPathExpressionException {
  Element ref = xml.getDocumentElement();
  for (int i = 0; i < path.length - 1; i++) {
    NodeList nodes = ref.getChildNodes();
    if (nodes.getLength() < 1) {
      return null;
    }
    Element elem;
    for (int j = 0; j < nodes.getLength(); j++) {
      if (nodes.item(j).getNodeType() == Node.ELEMENT_NODE) {
        elem = (Element) nodes.item(j);
        if (elem.getNodeName().equals(path[i]) && elem.getNamespaceURI().equals(namespaceUri)) {
          ref = elem;
          break;
        }
      }
    }
  }
  return ref.getElementsByTagNameNS(namespaceUri, path[path.length - 1]);
}

代码示例来源:origin: geotools/geotools

public void testEncodeSpatial() throws Exception {
  Document doc = encode(FilterMockData.intersects(), OGC.Filter);
  assertEquals("ogc:Filter", doc.getDocumentElement().getNodeName());
  assertEquals(1, doc.getElementsByTagNameNS(OGC.NAMESPACE, "Intersects").getLength());
}

代码示例来源:origin: stackoverflow.com

DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
 DocumentBuilder db = dbf.newDocumentBuilder();
 Document dom = db.parse("file.xml");
 Element docEle = dom.getDocumentElement();
 NodeList nl = docEle.getChildNodes();
 if (nl != null) {
   int length = nl.getLength();
   for (int i = 0; i < length; i++) {
     if (nl.item(i).getNodeType() == Node.ELEMENT_NODE) {
       Element el = (Element) nl.item(i);
       if (el.getNodeName().contains("staff")) {
         String name = el.getElementsByTagName("name").item(0).getTextContent();
         String phone = el.getElementsByTagName("phone").item(0).getTextContent();
         String email = el.getElementsByTagName("email").item(0).getTextContent();
         String area = el.getElementsByTagName("area").item(0).getTextContent();
         String city = el.getElementsByTagName("city").item(0).getTextContent();
       }
     }
   }
 }

相关文章

微信公众号

最新文章

更多