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

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

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

Element.getTextContent介绍

暂无

代码示例

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

  1. private void addToDependencyMapFromXML (Map<String, List<ExternalExtensionDependency>> dependencies, Element eElement, String platform) {
  2. if (eElement.getElementsByTagName(platform).item(0) != null) {
  3. Element project = (Element)eElement.getElementsByTagName(platform).item(0);
  4. ArrayList<ExternalExtensionDependency> deps = new ArrayList<ExternalExtensionDependency>();
  5. if (project.getTextContent().trim().equals("")) {
  6. // No dependencies required
  7. } else if (project.getTextContent().trim().equals("null")) {
  8. // Not supported
  9. deps = null;
  10. } else {
  11. NodeList nList = project.getElementsByTagName("dependency");
  12. for (int i = 0; i < nList.getLength(); i++) {
  13. Node nNode = nList.item(i);
  14. if (nNode.getNodeType() == Node.ELEMENT_NODE) {
  15. Element dependencyNode = (Element)nNode;
  16. boolean external = Boolean.parseBoolean(dependencyNode.getAttribute("external"));
  17. deps.add(new ExternalExtensionDependency(dependencyNode.getTextContent(), external));
  18. }
  19. }
  20. }
  21. dependencies.put(platform, deps);
  22. }
  23. }

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

  1. private String readElement(Document xmlDoc, String localName, String namespaceURI) {
  2. Element el = (Element)xmlDoc.getDocumentElement().getElementsByTagNameNS(namespaceURI, localName).item(0);
  3. if (el == null) {
  4. return null;
  5. }
  6. return el.getTextContent();
  7. }

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

  1. public static Map<String, String> getStyle(final Element stylesElement) {
  2. final Map<String, String> styles = new HashMap<>();
  3. if (stylesElement == null) {
  4. return styles;
  5. }
  6. for (final Element styleElement : getChildrenByTagName(stylesElement, "style")) {
  7. final String styleName = styleElement.getAttribute("name");
  8. final String styleValue = styleElement.getTextContent();
  9. styles.put(styleName, styleValue);
  10. }
  11. return styles;
  12. }

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

  1. public List<String> styles() throws Exception {
  2. Element styleRoot = ReaderUtils.getChildElement(coverage, "styles");
  3. if (styleRoot != null) {
  4. List<String> styleNames = new ArrayList<String>();
  5. Element[] styles = ReaderUtils.getChildElements(styleRoot, "style");
  6. for (Element style : styles) {
  7. styleNames.add(style.getTextContent().trim());
  8. }
  9. return styleNames;
  10. } else {
  11. return Collections.emptyList();
  12. }
  13. }

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

  1. private Object parseGrant(Element element, ParserContext parserContext) {
  2. BeanDefinitionBuilder builder = BeanDefinitionBuilder.genericBeanDefinition(AuthGrant.class);
  3. // role, user
  4. String[] users = split(element.getAttribute("user"), ", ");
  5. String[] roles = split(element.getAttribute("role"), ", ");
  6. builder.addPropertyValue("users", users);
  7. builder.addPropertyValue("roles", roles);
  8. // allow, deny
  9. ElementSelector allowSelector = and(sameNs(element), name("allow"));
  10. ElementSelector denySelector = and(sameNs(element), name("deny"));
  11. List<Object> allows = createManagedList(element, parserContext);
  12. List<Object> denies = createManagedList(element, parserContext);
  13. for (Element subElement : subElements(element, or(allowSelector, denySelector))) {
  14. String action = trimToNull(subElement.getTextContent());
  15. if (allowSelector.accept(subElement)) {
  16. allows.add(action);
  17. } else {
  18. denies.add(action);
  19. }
  20. }
  21. builder.addPropertyValue("allow", allows);
  22. builder.addPropertyValue("deny", denies);
  23. return builder.getBeanDefinition();
  24. }

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

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

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

  1. /**
  2. * 转换 未定义XML 字段为 Map
  3. * @since 2.8.13
  4. * @return MAP
  5. */
  6. public Map<String, String> otherElementsToMap() {
  7. Map<String, String> map = new LinkedHashMap<String, String>();
  8. if (otherElements != null) {
  9. for (org.w3c.dom.Element e : otherElements) {
  10. if (e.hasChildNodes()) {
  11. if (e.getChildNodes().getLength() == 1
  12. && e.getChildNodes().item(0).getNodeType() == Node.TEXT_NODE) {
  13. map.put(e.getTagName(), e.getTextContent());
  14. }
  15. }
  16. }
  17. }
  18. return map;
  19. }

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

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

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

  1. static String cellValue(Node theRowXml, int theCellIndex) {
  2. NodeList cells = ((Element) theRowXml).getElementsByTagName("Cell");
  3. for (int i = 0, currentCell = 0; i < cells.getLength(); i++) {
  4. Element nextCell = (Element) cells.item(i);
  5. String indexVal = nextCell.getAttributeNS("urn:schemas-microsoft-com:office:spreadsheet", "Index");
  6. if (StringUtils.isNotBlank(indexVal)) {
  7. // 1-indexed for some reason...
  8. currentCell = Integer.parseInt(indexVal) - 1;
  9. }
  10. if (currentCell == theCellIndex) {
  11. NodeList dataElems = nextCell.getElementsByTagName("Data");
  12. Element dataElem = (Element) dataElems.item(0);
  13. if (dataElem == null) {
  14. return null;
  15. }
  16. String retVal = dataElem.getTextContent();
  17. return retVal;
  18. }
  19. currentCell++;
  20. }
  21. return null;
  22. }

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

  1. private Map<String, String> extractModulesWithVersionAttribute(Element configRoot, String elementName,
  2. String elementParentName) {
  3. NodeList parents = configRoot.getElementsByTagName(elementParentName);
  4. Map<String, String> result = new HashMap<>();
  5. if (parents.getLength() == 0) {
  6. return result;
  7. }
  8. Element firstParent = (Element) parents.item(0);
  9. NodeList children = firstParent.getElementsByTagName(elementName);
  10. int i = 0;
  11. while (i < children.getLength()) {
  12. Element child = (Element) children.item(i);
  13. Attr versionAttribute = child.getAttributeNode("version");
  14. String version = versionAttribute == null ? null : versionAttribute.getValue();
  15. result.put(child.getTextContent().trim(), version);
  16. i++;
  17. }
  18. return result;
  19. }

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

  1. Element title = XMLUtil.getNamedChild(doc.getDocumentElement(), "Title");
  2. vs.setVersion(title.getAttribute("version"));
  3. vs.setName(title.getAttribute("name"));
  4. vs.setImmutable(true);
  5. Element identifier = XMLUtil.getNamedChild(doc.getDocumentElement(), "Identifier");
  6. vs.setPublisher(identifier.getAttribute("authority"));
  7. vs.addIdentifier(new Identifier().setValue(identifier.getAttribute("uid")));
  8. List<Element> authors = new ArrayList<Element>();
  9. XMLUtil.getNamedChildren(XMLUtil.getNamedChild(doc.getDocumentElement(), "Authors"), "Author", authors);
  10. for (Element a : authors)
  11. if (!a.getAttribute("name").contains("+"))
  12. vs.addContact().setName(a.getTextContent());
  13. 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");
  14. vs.setStatus(PublicationStatus.ACTIVE);
  15. for (Element a : authors)
  16. if (!a.getAttribute("name").contains("+"))
  17. cs.addContact().setName(a.getTextContent());
  18. 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");
  19. cs.setStatus(PublicationStatus.ACTIVE);

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

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

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

  1. public static Map<String, Object> loadElements(Element parent) {
  2. Map<String, Object> map = new HashMap<String, Object>();
  3. NodeList children = parent.getChildNodes();
  4. for (int i = 0; i < children.getLength(); i++) {
  5. Node node = children.item(i);
  6. if (node instanceof Element) {
  7. Element e = (Element) node;
  8. String name = e.getNodeName();
  9. if ("property".equals(name)) {
  10. String key = e.getAttribute("name");
  11. NodeList nl = e.getElementsByTagName("bean");
  12. if (nl.getLength() == 0) {
  13. String value = e.getTextContent();
  14. map.put(key, StringUtil.isEmpty(value) ? null : value.trim());
  15. } else {
  16. map.put(key, loadBean((Element) nl.item(0)));
  17. }
  18. }
  19. }
  20. }
  21. return map;
  22. }

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

  1. public List<String> styles() throws Exception {
  2. Element styleRoot = ReaderUtils.getChildElement(featureType, "styles");
  3. if (styleRoot != null) {
  4. List<String> styleNames = new ArrayList<String>();
  5. Element[] styles = ReaderUtils.getChildElements(styleRoot, "style");
  6. for (Element style : styles) {
  7. styleNames.add(style.getTextContent().trim());
  8. }
  9. return styleNames;
  10. } else {
  11. return Collections.emptyList();
  12. }
  13. }

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

  1. private Object parseGrant(Element element, ParserContext parserContext) {
  2. BeanDefinitionBuilder builder = BeanDefinitionBuilder.genericBeanDefinition(AuthGrant.class);
  3. // role, user
  4. String[] users = split(element.getAttribute("user"), ", ");
  5. String[] roles = split(element.getAttribute("role"), ", ");
  6. builder.addPropertyValue("users", users);
  7. builder.addPropertyValue("roles", roles);
  8. // allow, deny
  9. ElementSelector allowSelector = and(sameNs(element), name("allow"));
  10. ElementSelector denySelector = and(sameNs(element), name("deny"));
  11. List<Object> allows = createManagedList(element, parserContext);
  12. List<Object> denies = createManagedList(element, parserContext);
  13. for (Element subElement : subElements(element, or(allowSelector, denySelector))) {
  14. String action = trimToNull(subElement.getTextContent());
  15. if (allowSelector.accept(subElement)) {
  16. allows.add(action);
  17. } else {
  18. denies.add(action);
  19. }
  20. }
  21. builder.addPropertyValue("allow", allows);
  22. builder.addPropertyValue("deny", denies);
  23. return builder.getBeanDefinition();
  24. }

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

  1. /**
  2. * XML节点转换为Map
  3. *
  4. * @param node XML节点
  5. * @param result 结果Map类型
  6. * @return XML数据转换后的Map
  7. * @since 4.0.8
  8. */
  9. public static Map<String, Object> xmlToMap(Node node, Map<String, Object> result) {
  10. if (null == result) {
  11. result = new HashMap<>();
  12. }
  13. final NodeList nodeList = node.getChildNodes();
  14. final int length = nodeList.getLength();
  15. Node childNode;
  16. Element childEle;
  17. for (int i = 0; i < length; ++i) {
  18. childNode = nodeList.item(i);
  19. if (isElement(childNode)) {
  20. childEle = (Element) childNode;
  21. result.put(childEle.getNodeName(), childEle.getTextContent());
  22. }
  23. }
  24. return result;
  25. }

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

  1. private String getRooProjectVersion() {
  2. String homePath = new File(".").getPath();
  3. String pomPath = homePath + "/pom.xml";
  4. File pom = new File(pomPath);
  5. try {
  6. if (pom.exists()) {
  7. InputStream is = new FileInputStream(pom);
  8. Document docXml = XmlUtils.readXml(is);
  9. Element document = docXml.getDocumentElement();
  10. Element rooVersionElement = XmlUtils.findFirstElement("properties/roo.version", document);
  11. String rooVersion = rooVersionElement.getTextContent();
  12. return rooVersion;
  13. }
  14. return "UNKNOWN";
  15. } catch (FileNotFoundException e) {
  16. e.printStackTrace();
  17. }
  18. return "";
  19. }

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

  1. public static DroolsAction extractAction(Element xmlNode) {
  2. String actionType = xmlNode.getAttribute("type");
  3. if ("expression".equals(actionType)) {
  4. String consequence = xmlNode.getTextContent();
  5. DroolsConsequenceAction action = new DroolsConsequenceAction(xmlNode.getAttribute("dialect"), consequence);
  6. return action;
  7. } else {
  8. throw new IllegalArgumentException(
  9. "Unknown action type " + actionType);
  10. }
  11. }

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

  1. private synchronized void launchBrowser() {
  2. try {
  3. // Note, we use standard DOM to read in the XML. This is necessary so that
  4. // Launcher has fewer dependencies.
  5. DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
  6. Document document = factory.newDocumentBuilder().parse(configFile);
  7. Element rootElement = document.getDocumentElement();
  8. Element adminElement = (Element)rootElement.getElementsByTagName("adminConsole").item(0);
  9. String port = "-1";
  10. String securePort = "-1";
  11. Element portElement = (Element)adminElement.getElementsByTagName("port").item(0);
  12. if (portElement != null) {
  13. port = portElement.getTextContent();
  14. }
  15. Element securePortElement = (Element)adminElement.getElementsByTagName("securePort").item(0);
  16. if (securePortElement != null) {
  17. securePort = securePortElement.getTextContent();
  18. }
  19. if ("-1".equals(port)) {
  20. Desktop.getDesktop().browse(URI.create("https://127.0.0.1:" + securePort + "/index.html"));
  21. } else {
  22. Desktop.getDesktop().browse(URI.create("http://127.0.0.1:" + port + "/index.html"));
  23. }
  24. }
  25. catch (Exception e) {
  26. // Make sure to print the exception
  27. e.printStackTrace(System.out);
  28. JOptionPane.showMessageDialog(new JFrame(), configFile + " " + e.getMessage());
  29. }
  30. }

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

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

相关文章