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

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

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

Element.getTextContent介绍

暂无

代码示例

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

private void addToDependencyMapFromXML (Map<String, List<ExternalExtensionDependency>> dependencies, Element eElement, String platform) {
  if (eElement.getElementsByTagName(platform).item(0) != null) {
    Element project = (Element)eElement.getElementsByTagName(platform).item(0);
    ArrayList<ExternalExtensionDependency> deps = new ArrayList<ExternalExtensionDependency>();
    if (project.getTextContent().trim().equals("")) {
      // No dependencies required
    } else if (project.getTextContent().trim().equals("null")) {
      // Not supported
      deps = null;
    } else {
      NodeList nList = project.getElementsByTagName("dependency");
      for (int i = 0; i < nList.getLength(); i++) {
        Node nNode = nList.item(i);
        if (nNode.getNodeType() == Node.ELEMENT_NODE) {
          Element dependencyNode = (Element)nNode;
          boolean external = Boolean.parseBoolean(dependencyNode.getAttribute("external"));
          deps.add(new ExternalExtensionDependency(dependencyNode.getTextContent(), external));
        }
      }
    }
    dependencies.put(platform, deps);
  }
}

代码示例来源:origin: org.apache.poi/poi-ooxml

private String readElement(Document xmlDoc, String localName, String namespaceURI) {
  Element el = (Element)xmlDoc.getDocumentElement().getElementsByTagNameNS(namespaceURI, localName).item(0);
  if (el == null) {
    return null;
  }
  return el.getTextContent();
}

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

public static Map<String, String> getStyle(final Element stylesElement) {
  final Map<String, String> styles = new HashMap<>();
  if (stylesElement == null) {
    return styles;
  }
  for (final Element styleElement : getChildrenByTagName(stylesElement, "style")) {
    final String styleName = styleElement.getAttribute("name");
    final String styleValue = styleElement.getTextContent();
    styles.put(styleName, styleValue);
  }
  return styles;
}

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

public List<String> styles() throws Exception {
  Element styleRoot = ReaderUtils.getChildElement(coverage, "styles");
  if (styleRoot != null) {
    List<String> styleNames = new ArrayList<String>();
    Element[] styles = ReaderUtils.getChildElements(styleRoot, "style");
    for (Element style : styles) {
      styleNames.add(style.getTextContent().trim());
    }
    return styleNames;
  } else {
    return Collections.emptyList();
  }
}

代码示例来源:origin: webx/citrus

private Object parseGrant(Element element, ParserContext parserContext) {
  BeanDefinitionBuilder builder = BeanDefinitionBuilder.genericBeanDefinition(AuthGrant.class);
  // role, user
  String[] users = split(element.getAttribute("user"), ", ");
  String[] roles = split(element.getAttribute("role"), ", ");
  builder.addPropertyValue("users", users);
  builder.addPropertyValue("roles", roles);
  // allow, deny
  ElementSelector allowSelector = and(sameNs(element), name("allow"));
  ElementSelector denySelector = and(sameNs(element), name("deny"));
  List<Object> allows = createManagedList(element, parserContext);
  List<Object> denies = createManagedList(element, parserContext);
  for (Element subElement : subElements(element, or(allowSelector, denySelector))) {
    String action = trimToNull(subElement.getTextContent());
    if (allowSelector.accept(subElement)) {
      allows.add(action);
    } else {
      denies.add(action);
    }
  }
  builder.addPropertyValue("allow", allows);
  builder.addPropertyValue("deny", denies);
  return builder.getBeanDefinition();
}

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

final Element rootElement = document.getDocumentElement();
final Element rootGroupElement = (Element) rootElement.getElementsByTagName("rootGroup").item(0);
if (rootGroupElement == null) {
  logger.warn("rootGroup element not found in Flow Configuration file");
final Element rootGroupIdElement = (Element) rootGroupElement.getElementsByTagName("id").item(0);
if (rootGroupIdElement == null) {
  logger.warn("id element not found under rootGroup in Flow Configuration file");
final String rootGroupId = rootGroupIdElement.getTextContent();

代码示例来源:origin: liyiorg/weixin-popular

/**
 * 转换 未定义XML 字段为 Map
 * @since 2.8.13
 * @return MAP
 */
public Map<String, String> otherElementsToMap() {
  Map<String, String> map = new LinkedHashMap<String, String>();
  if (otherElements != null) {
    for (org.w3c.dom.Element e : otherElements) {
      if (e.hasChildNodes()) {
        if (e.getChildNodes().getLength() == 1
            && e.getChildNodes().item(0).getNodeType() == Node.TEXT_NODE) {
          map.put(e.getTagName(), e.getTextContent());
        }
      }
    }
  }
  return map;
}

代码示例来源:origin: spring-projects/spring-framework

@Test
public void readDOMSourceExternal() throws Exception {
  MockHttpInputMessage inputMessage = new MockHttpInputMessage(bodyExternal.getBytes("UTF-8"));
  inputMessage.getHeaders().setContentType(new MediaType("application", "xml"));
  converter.setSupportDtd(true);
  DOMSource result = (DOMSource) converter.read(DOMSource.class, inputMessage);
  Document document = (Document) result.getNode();
  assertEquals("Invalid result", "root", document.getDocumentElement().getLocalName());
  assertNotEquals("Invalid result", "Foo Bar", document.getDocumentElement().getTextContent());
}

代码示例来源:origin: jamesagnew/hapi-fhir

static String cellValue(Node theRowXml, int theCellIndex) {
  NodeList cells = ((Element) theRowXml).getElementsByTagName("Cell");
  for (int i = 0, currentCell = 0; i < cells.getLength(); i++) {
    Element nextCell = (Element) cells.item(i);
    String indexVal = nextCell.getAttributeNS("urn:schemas-microsoft-com:office:spreadsheet", "Index");
    if (StringUtils.isNotBlank(indexVal)) {
      // 1-indexed for some reason...
      currentCell = Integer.parseInt(indexVal) - 1;
    }
    if (currentCell == theCellIndex) {
      NodeList dataElems = nextCell.getElementsByTagName("Data");
      Element dataElem = (Element) dataElems.item(0);
      if (dataElem == null) {
        return null;
      }
      String retVal = dataElem.getTextContent();
      return retVal;
    }
    currentCell++;
  }
  return null;
}

代码示例来源:origin: openmrs/openmrs-core

private Map<String, String> extractModulesWithVersionAttribute(Element configRoot, String elementName,
  String elementParentName) {
  
  NodeList parents = configRoot.getElementsByTagName(elementParentName);
  
  Map<String, String> result = new HashMap<>();
  if (parents.getLength() == 0) {
    return result;
  }
  
  Element firstParent = (Element) parents.item(0);
  NodeList children = firstParent.getElementsByTagName(elementName);
  
  int i = 0;
  while (i < children.getLength()) {
    Element child = (Element) children.item(i);
    Attr versionAttribute = child.getAttributeNode("version");
    String version = versionAttribute == null ? null : versionAttribute.getValue();
    result.put(child.getTextContent().trim(), version);
    i++;
  }
  return result;
}

代码示例来源:origin: jamesagnew/hapi-fhir

Element title = XMLUtil.getNamedChild(doc.getDocumentElement(), "Title");
vs.setVersion(title.getAttribute("version"));
vs.setName(title.getAttribute("name"));
vs.setImmutable(true);
Element identifier = XMLUtil.getNamedChild(doc.getDocumentElement(), "Identifier");
vs.setPublisher(identifier.getAttribute("authority"));
vs.addIdentifier(new Identifier().setValue(identifier.getAttribute("uid")));
List<Element> authors = new ArrayList<Element>(); 
XMLUtil.getNamedChildren(XMLUtil.getNamedChild(doc.getDocumentElement(), "Authors"), "Author", authors);
for (Element a : authors)
 if (!a.getAttribute("name").contains("+"))
  vs.addContact().setName(a.getTextContent());
vs.setCopyright("The copyright of ICPC, both in hard copy and in electronic form, is owned by Wonca. See http://www.kith.no/templates/kith_WebPage____1110.aspx");
vs.setStatus(PublicationStatus.ACTIVE);
for (Element a : authors)
 if (!a.getAttribute("name").contains("+"))
  cs.addContact().setName(a.getTextContent());
cs.setCopyright("The copyright of ICPC, both in hard copy and in electronic form, is owned by Wonca. See http://www.kith.no/templates/kith_WebPage____1110.aspx");
cs.setStatus(PublicationStatus.ACTIVE);

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

final String className = childNodes.item(0).getTextContent();
appendFirstValue(builder, childNodes);
final List<Element> sortedPropertyElems = sortElements(propertyElems, getProcessorPropertiesComparator());
for (final Element propertyElem : sortedPropertyElems) {
  final String propName = DomUtils.getChildElementsByTagName(propertyElem, "name").get(0).getTextContent();
  String propValue = getFirstValue(DomUtils.getChildNodesByTagName(propertyElem, "value"), null);
  addPropertyFingerprint(builder, configurableComponent, propName, propValue);
final List<Element> sortedAutoTerminateElems = sortElements(autoTerminateElems, getElementTextComparator());
for (final Element autoTerminateElem : sortedAutoTerminateElems) {
  builder.append(autoTerminateElem.getTextContent());

代码示例来源:origin: alibaba/cobar

public static Map<String, Object> loadElements(Element parent) {
  Map<String, Object> map = new HashMap<String, Object>();
  NodeList children = parent.getChildNodes();
  for (int i = 0; i < children.getLength(); i++) {
    Node node = children.item(i);
    if (node instanceof Element) {
      Element e = (Element) node;
      String name = e.getNodeName();
      if ("property".equals(name)) {
        String key = e.getAttribute("name");
        NodeList nl = e.getElementsByTagName("bean");
        if (nl.getLength() == 0) {
          String value = e.getTextContent();
          map.put(key, StringUtil.isEmpty(value) ? null : value.trim());
        } else {
          map.put(key, loadBean((Element) nl.item(0)));
        }
      }
    }
  }
  return map;
}

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

public List<String> styles() throws Exception {
  Element styleRoot = ReaderUtils.getChildElement(featureType, "styles");
  if (styleRoot != null) {
    List<String> styleNames = new ArrayList<String>();
    Element[] styles = ReaderUtils.getChildElements(styleRoot, "style");
    for (Element style : styles) {
      styleNames.add(style.getTextContent().trim());
    }
    return styleNames;
  } else {
    return Collections.emptyList();
  }
}

代码示例来源:origin: webx/citrus

private Object parseGrant(Element element, ParserContext parserContext) {
  BeanDefinitionBuilder builder = BeanDefinitionBuilder.genericBeanDefinition(AuthGrant.class);
  // role, user
  String[] users = split(element.getAttribute("user"), ", ");
  String[] roles = split(element.getAttribute("role"), ", ");
  builder.addPropertyValue("users", users);
  builder.addPropertyValue("roles", roles);
  // allow, deny
  ElementSelector allowSelector = and(sameNs(element), name("allow"));
  ElementSelector denySelector = and(sameNs(element), name("deny"));
  List<Object> allows = createManagedList(element, parserContext);
  List<Object> denies = createManagedList(element, parserContext);
  for (Element subElement : subElements(element, or(allowSelector, denySelector))) {
    String action = trimToNull(subElement.getTextContent());
    if (allowSelector.accept(subElement)) {
      allows.add(action);
    } else {
      denies.add(action);
    }
  }
  builder.addPropertyValue("allow", allows);
  builder.addPropertyValue("deny", denies);
  return builder.getBeanDefinition();
}

代码示例来源: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: spring-projects/spring-roo

private String getRooProjectVersion() {
 String homePath = new File(".").getPath();
 String pomPath = homePath + "/pom.xml";
 File pom = new File(pomPath);
 try {
  if (pom.exists()) {
   InputStream is = new FileInputStream(pom);
   Document docXml = XmlUtils.readXml(is);
   Element document = docXml.getDocumentElement();
   Element rooVersionElement = XmlUtils.findFirstElement("properties/roo.version", document);
   String rooVersion = rooVersionElement.getTextContent();
   return rooVersion;
  }
  return "UNKNOWN";
 } catch (FileNotFoundException e) {
  e.printStackTrace();
 }
 return "";
}

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

public static DroolsAction extractAction(Element xmlNode) {
  String actionType = xmlNode.getAttribute("type");
  if ("expression".equals(actionType)) {
    String consequence = xmlNode.getTextContent();
    DroolsConsequenceAction action = new DroolsConsequenceAction(xmlNode.getAttribute("dialect"), consequence);
    return action;
  } else {
    throw new IllegalArgumentException(
      "Unknown action type " + actionType);
  }
}

代码示例来源:origin: igniterealtime/Openfire

private synchronized void launchBrowser() {
  try {
    // Note, we use standard DOM to read in the XML. This is necessary so that
    // Launcher has fewer dependencies.
    DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
    Document document = factory.newDocumentBuilder().parse(configFile);
    Element rootElement = document.getDocumentElement();
    Element adminElement = (Element)rootElement.getElementsByTagName("adminConsole").item(0);
    String port = "-1";
    String securePort = "-1";
    Element portElement = (Element)adminElement.getElementsByTagName("port").item(0);
    if (portElement != null) {
      port = portElement.getTextContent();
    }
    Element securePortElement = (Element)adminElement.getElementsByTagName("securePort").item(0);
    if (securePortElement != null) {
      securePort = securePortElement.getTextContent();
    }
    if ("-1".equals(port)) {
      Desktop.getDesktop().browse(URI.create("https://127.0.0.1:" + securePort + "/index.html"));
    } else {
      Desktop.getDesktop().browse(URI.create("http://127.0.0.1:" + port + "/index.html"));
    }
  }
  catch (Exception e) {
    // Make sure to print the exception
    e.printStackTrace(System.out);
    JOptionPane.showMessageDialog(new JFrame(), configFile + " " + e.getMessage());
  }
}

代码示例来源:origin: stanfordnlp/CoreNLP

DocumentBuilder db = dbf.newDocumentBuilder();
Document doc = db.parse(f);
doc.getDocumentElement().normalize();
for (int i = 0; i < nodeList.getLength(); i++) {
 Element element = (Element)nodeList.item(i);
 String raw = element.getTextContent();
 StringBuilder builtUp = new StringBuilder();
 boolean inTag = false;
 sents.add(builtUp.toString());

相关文章

微信公众号

最新文章

更多