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

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

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

Element.hasChildNodes介绍

暂无

代码示例

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

  1. private static boolean isWordNode(Element node) {
  2. return node.hasAttribute(ATTR_WORD) && !node.hasChildNodes();
  3. }

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

  1. private void extendBeanDefinition(Element element, ParserContext parserContext) {
  2. BeanDefinition beanDef =
  3. parserContext.getRegistry().getBeanDefinition(AopConfigUtils.AUTO_PROXY_CREATOR_BEAN_NAME);
  4. if (element.hasChildNodes()) {
  5. addIncludePatterns(element, parserContext, beanDef);
  6. }
  7. }

代码示例来源:origin: ehcache/ehcache3

  1. private static String val(Element element) {
  2. return element.hasChildNodes() ? element.getFirstChild().getNodeValue() : null;
  3. }

代码示例来源:origin: nutzam/nutz

  1. protected List<IocValue> paserCollection(Element element) throws Throwable {
  2. List<IocValue> list = new ArrayList<IocValue>();
  3. if (element.hasChildNodes()) {
  4. NodeList nodeList = element.getChildNodes();
  5. for (int i = 0; i < nodeList.getLength(); i++) {
  6. Node node = nodeList.item(i);
  7. if (node instanceof Element) {
  8. list.add((IocValue) parseX((Element) node));
  9. }
  10. }
  11. }
  12. return list;
  13. }

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

  1. /**
  2. * Common routine to remove all children nodes from the passed element container
  3. * @param parentElement
  4. * @param nodeName
  5. * @throws XPathExpressionException
  6. */
  7. protected void clearNode(Element parentElement, String nodeName) throws XPathExpressionException {
  8. if (parentElement.hasChildNodes()) {
  9. NodeList children = (NodeList) xPath.evaluate(nodeName, parentElement, XPathConstants.NODESET);
  10. for (int j = 0; j < children.getLength(); j++) {
  11. parentElement.removeChild(children.item(j));
  12. }
  13. children = parentElement.getChildNodes();
  14. for (int j = 0; j < children.getLength(); j++) {
  15. if (children.item(j).getNodeName().equalsIgnoreCase("#text")) {
  16. parentElement.removeChild(children.item(j));
  17. }
  18. }
  19. }
  20. }

代码示例来源:origin: nutzam/nutz

  1. protected Map<String, ?> paserMap(Element element) throws Throwable {
  2. Map<String, Object> map = new HashMap<String, Object>();
  3. if (element.hasChildNodes()) {
  4. List<Element> elist = getChildNodesByTagName(element, ITEM_TAG);
  5. for (Element elementItem : elist) {
  6. String key = elementItem.getAttribute("key");
  7. if (map.containsKey(key))
  8. throw new IllegalArgumentException("key is not unique!");
  9. NodeList list = elementItem.getChildNodes();
  10. for (int j = 0; j < list.getLength(); j++) {
  11. if (list.item(j) instanceof Element) {
  12. map.put(key, parseX((Element) list.item(j)));
  13. break;
  14. }
  15. }
  16. if (!map.containsKey(key))
  17. map.put(key, null);
  18. }
  19. }
  20. return map;
  21. }

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

  1. /**
  2. * Returns the list of any direct String nodes of this node.
  3. *
  4. * @return the list of String values from this node
  5. * @since 2.3.0
  6. */
  7. public static List<String> localText(Element self) {
  8. List<String> result = new ArrayList<String>();
  9. if (self.getNodeType() == Node.TEXT_NODE || self.getNodeType() == Node.CDATA_SECTION_NODE) {
  10. result.add(self.getNodeValue());
  11. } else if (self.hasChildNodes()) {
  12. NodeList nodeList = self.getChildNodes();
  13. for (int i = 0; i < nodeList.getLength(); i++) {
  14. Node item = nodeList.item(i);
  15. if (item.getNodeType() == Node.TEXT_NODE || item.getNodeType() == Node.CDATA_SECTION_NODE) {
  16. result.add(item.getNodeValue());
  17. }
  18. }
  19. }
  20. return result;
  21. }

代码示例来源:origin: plutext/docx4j

  1. case Node.ELEMENT_NODE :
  2. Element element = (Element) node;
  3. if (!element.hasChildNodes()) {
  4. break;

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

  1. continue;
  2. Element field = (Element)fieldNode;
  3. if ("name".equals(field.getTagName()) && field.hasChildNodes())
  4. attr = StringInterner.weakIntern(
  5. ((Text)field.getFirstChild()).getData().trim());
  6. if ("value".equals(field.getTagName()) && field.hasChildNodes())
  7. value = StringInterner.weakIntern(
  8. ((Text)field.getFirstChild()).getData());
  9. if ("final".equals(field.getTagName()) && field.hasChildNodes())
  10. finalParameter = "true".equals(((Text)field.getFirstChild()).getData());
  11. if ("source".equals(field.getTagName()) && field.hasChildNodes())
  12. source.add(StringInterner.weakIntern(
  13. ((Text)field.getFirstChild()).getData()));

代码示例来源:origin: nutzam/nutz

  1. protected void parseFields(Element beanElement, IocObject iocObject) throws Throwable {
  2. List<Element> list = getChildNodesByTagName(beanElement, TAG_FIELD);
  3. for (Element fieldElement : list) {
  4. IocField iocField = new IocField();
  5. iocField.setName(fieldElement.getAttribute("name"));
  6. if ("true".equals(fieldElement.getAttribute("optional")))
  7. iocField.setOptional(true);
  8. if (fieldElement.hasChildNodes()) {
  9. NodeList nodeList = fieldElement.getChildNodes();
  10. for (int j = 0; j < nodeList.getLength(); j++) {
  11. if (nodeList.item(j) instanceof Element) {
  12. iocField.setValue(parseX((Element) nodeList.item(j)));
  13. break;
  14. }
  15. }
  16. }
  17. iocObject.addField(iocField);
  18. }
  19. }

代码示例来源:origin: plutext/docx4j

  1. if (!thisSpan.hasChildNodes()) continue;

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

  1. ttl = extractIntAttribute(root, TTL_ATTR);
  2. if (!root.hasChildNodes()) {
  3. throw new IllegalArgumentException("Incorrect Cassandra persistence settings specification, " +
  4. "there are no key and value persistence settings specified");

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

  1. if (!document.getDocumentElement().hasChildNodes()) {

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

  1. if(e.hasChildNodes()){

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

  1. private void parseChildElements(Element element, String parentId, String redissonRef, BeanDefinitionBuilder redissonDef, ParserContext parserContext) {
  2. if (element.hasChildNodes()) {
  3. CompositeComponentDefinition compositeDef
  4. = new CompositeComponentDefinition(parentId,
  5. parserContext.extractSource(element));
  6. parserContext.pushContainingComponent(compositeDef);
  7. List<Element> childElts = DomUtils.getChildElements(element);
  8. for (Element elt : childElts) {
  9. if(BeanDefinitionParserDelegate
  10. .QUALIFIER_ELEMENT.equals(elt.getLocalName())) {
  11. continue;//parsed elsewhere
  12. }
  13. String localName = parserContext.getDelegate().getLocalName(elt);
  14. localName = Conventions.attributeNameToPropertyName(localName);
  15. if (ConfigType.contains(localName)) {
  16. parseConfigTypes(elt, localName, redissonDef, parserContext);
  17. } else if (AddressType.contains(localName)) {
  18. parseAddressTypes(elt, localName, redissonDef, parserContext);
  19. } else if (helper.isRedissonNS(elt)) {
  20. elt.setAttribute(REDISSON_REF, redissonRef);
  21. parserContext.getDelegate().parseCustomElement(elt);
  22. }
  23. }
  24. parserContext.popContainingComponent();
  25. }
  26. }

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

  1. private void parseChildElements(Element element, String parentId, String redissonRef, BeanDefinitionBuilder redissonDef, ParserContext parserContext) {
  2. if (element.hasChildNodes()) {
  3. CompositeComponentDefinition compositeDef
  4. = new CompositeComponentDefinition(parentId,
  5. parserContext.extractSource(element));
  6. parserContext.pushContainingComponent(compositeDef);
  7. List<Element> childElts = DomUtils.getChildElements(element);
  8. for (Element elt : childElts) {
  9. if(BeanDefinitionParserDelegate
  10. .QUALIFIER_ELEMENT.equals(elt.getLocalName())) {
  11. continue;//parsed elsewhere
  12. }
  13. String localName = parserContext.getDelegate().getLocalName(elt);
  14. localName = Conventions.attributeNameToPropertyName(localName);
  15. if (ConfigType.contains(localName)) {
  16. parseConfigTypes(elt, localName, redissonDef, parserContext);
  17. } else if (AddressType.contains(localName)) {
  18. parseAddressTypes(elt, localName, redissonDef, parserContext);
  19. } else if (helper.isRedissonNS(elt)) {
  20. elt.setAttribute(REDISSON_REF, redissonRef);
  21. parserContext.getDelegate().parseCustomElement(elt);
  22. }
  23. }
  24. parserContext.popContainingComponent();
  25. }
  26. }

代码示例来源:origin: plutext/docx4j

  1. && !xhtmlBlock.hasChildNodes() ) {

代码示例来源:origin: rhuss/jolokia

  1. /** {@inheritDoc} */
  2. public Object extract(Element element) { return element.hasChildNodes(); }
  3. }

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

  1. private boolean hasParameters(Element root) {
  2. // check if any attribute is parametric
  3. NamedNodeMap attributes = root.getAttributes();
  4. for (int i = 0; i < attributes.getLength(); i++) {
  5. Node attribute = attributes.item(i);
  6. final String nv = attribute.getNodeValue();
  7. if (nv != null && nv.contains("param(")) {
  8. return true;
  9. }
  10. }
  11. // recurse
  12. if (root.hasChildNodes()) {
  13. NodeList childNodes = root.getChildNodes();
  14. for (int i = 0; i < childNodes.getLength(); i++) {
  15. Node n = childNodes.item(i);
  16. if (n != null && n instanceof Element) {
  17. if (hasParameters((Element) n)) {
  18. return true;
  19. }
  20. }
  21. }
  22. }
  23. return true;
  24. }

相关文章