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

x33g5p2x  于2022-01-24 转载在 其他  
字(9.9k)|赞(0)|评价(0)|浏览(202)

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

Node.hasAttributes介绍

[英]Returns whether this node (if it is an element) has any attributes.
[中]返回此节点(如果是元素)是否具有任何属性。

代码示例

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

@Override
public boolean hasAttributes() {
  return node.hasAttributes();
}

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

/**
 * @see org.w3c.dom.Node#hasAttributes()
 */
public boolean hasAttributes() {
  return m_attributeNode.hasAttributes();
}

代码示例来源:origin: skylot/jadx

private void parseAttrList(NodeList nodeList) {
  for (int count = 0; count < nodeList.getLength(); count++) {
    Node tempNode = nodeList.item(count);
    if (tempNode.getNodeType() == Node.ELEMENT_NODE
        && tempNode.hasAttributes()
        && tempNode.hasChildNodes()) {
      String name = null;
      NamedNodeMap nodeMap = tempNode.getAttributes();
      for (int i = 0; i < nodeMap.getLength(); i++) {
        Node node = nodeMap.item(i);
        if (node.getNodeName().equals("name")) {
          name = node.getNodeValue();
          break;
        }
      }
      if (name != null && tempNode.getNodeName().equals("attr")) {
        parseValues(name, tempNode.getChildNodes());
      } else {
        parseAttrList(tempNode.getChildNodes());
      }
    }
  }
}

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

/**
 * Climb through <code>node</code>'s ancestors, looking for one with an attribute named <code>attributeName</code>,
 * irrespective of the respective <code>ancestorName</code>, and return the attribute's value
 * 
 * @param node
 *            node
 * @param attributeName
 *            attributeName
 * @return value of attribute from closest ancestor with that attribute, or the empty string if no ancestor has that
 *         attribute.
 * 
 */
public static String getAttributeFromClosestAncestorOfAnyKind(Node node, String attributeName) {
  Node parentNode;
  while (node != null && (parentNode = node.getParentNode()) != null) {
    if (parentNode.hasAttributes()) {
      Element parentElement = (Element) parentNode;
      if (parentElement.hasAttribute(attributeName)) {
        return parentElement.getAttribute(attributeName);
      }
    }
    node = parentNode;
  }
  return "";
}

代码示例来源:origin: pentaho/pentaho-kettle

private void removeEmptyNodes( NodeList nodes ) {
  for ( int i = 0; i < nodes.getLength(); i++ ) {
   Node node = nodes.item( i );

   // Process the tree bottom-up
   if ( node.hasChildNodes() ) {
    removeEmptyNodes( node.getChildNodes() );
   }

   boolean nodeIsEmpty =
     node.getNodeType() == Node.ELEMENT_NODE && !node.hasAttributes() && !node.hasChildNodes()
       && node.getTextContent().length() == 0;

   if ( nodeIsEmpty ) {
    // We shifted elements left, do not increment counter
    node.getParentNode().removeChild( node );
    i--;
   }
  }
 }
}

代码示例来源:origin: skylot/jadx

Node tempNode = nodeList.item(count);
if (tempNode.getNodeType() == Node.ELEMENT_NODE
    && tempNode.hasAttributes()) {
  if (attr == null) {
    if (tempNode.getNodeName().equals("enum")) {

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

/**
 * Climb through <code>node</code>'s ancestors, looking for one with an attribute named <code>attributeName</code>,
 * irrespective of the respective <code>ancestorName</code>, and return the attribute's value
 * 
 * @param node
 *            node
 * @param attributeName
 *            attributeName
 * @return value of attribute from closest ancestor with that attribute, or the empty string if no ancestor has that
 *         attribute.
 * 
 */
public static String getAttributeFromClosestAncestorOfAnyKind(Node node, String attributeName) {
  Node parentNode;
  while (node != null && (parentNode = node.getParentNode()) != null) {
    if (parentNode.hasAttributes()) {
      Element parentElement = (Element) parentNode;
      if (parentElement.hasAttribute(attributeName)) {
        return parentElement.getAttribute(attributeName);
      }
    }
    node = parentNode;
  }
  return "";
}

代码示例来源:origin: org.testng/testng

public List<Object[]> getParameters(Element element) {
  List<Object[]> allParameters = Lists.newArrayList();
  if (m_onElement != null) {
   List<Object> result = Lists.newArrayList();
   for (String attributeName : m_onElement.attributes()) {
    result.add(element.getAttribute(attributeName));
   }
   allParameters.add(result.toArray());
  } else if (m_tag != null) {
   List<Object> result = Lists.newArrayList();
   result.add(m_bean);
   allParameters.add(result.toArray());
  } else {
   NodeList childNodes = element.getChildNodes();
   for (int i = 0; i < childNodes.getLength(); i++) {
    if (childNodes.item(i).hasAttributes()) {
     Element item = (Element) childNodes.item(i);
     List<Object> result = Lists.newArrayList();
     for (String attributeName : m_onElementList.attributes()) {
      result.add(item.getAttribute(attributeName));
     }
     allParameters.add(result.toArray());
    }
   }
  }

  return allParameters;
 }
}

代码示例来源:origin: cbeust/testng

public List<Object[]> getParameters(Element element) {
  List<Object[]> allParameters = Lists.newArrayList();
  if (m_onElement != null) {
   List<Object> result = Lists.newArrayList();
   for (String attributeName : m_onElement.attributes()) {
    result.add(element.getAttribute(attributeName));
   }
   allParameters.add(result.toArray());
  } else if (m_tag != null) {
   List<Object> result = Lists.newArrayList();
   result.add(m_bean);
   allParameters.add(result.toArray());
  } else {
   NodeList childNodes = element.getChildNodes();
   for (int i = 0; i < childNodes.getLength(); i++) {
    if (childNodes.item(i).hasAttributes()) {
     Element item = (Element) childNodes.item(i);
     List<Object> result = Lists.newArrayList();
     for (String attributeName : m_onElementList.attributes()) {
      result.add(item.getAttribute(attributeName));
     }
     allParameters.add(result.toArray());
    }
   }
  }

  return allParameters;
 }
}

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

if (n.hasAttributes()) {
  NamedNodeMap atts = n.getAttributes();
  int length = atts.getLength();

代码示例来源:origin: org.apache.ant/ant

if (node.hasAttributes()) {
if (node.getNodeType() == Node.ELEMENT_NODE
    && semanticAttributes
    && node.hasAttributes()
    && (node.getAttributes().getNamedItem(VALUE) != null
        || node.getAttributes().getNamedItem(LOCATION) != null

代码示例来源:origin: jphp-group/jphp

if (el.hasAttributes() || el.hasChildNodes()) {
  if (el.getChildNodes().getLength() == 1 && el.getFirstChild().getNodeType() == Node.TEXT_NODE) {
    ReferenceMemory one = result.getByScalar(el.getNodeName());

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

private static String getFirstAttribute(Node node, String ns, String name) {
  if (node.hasAttributes()) {
    NamedNodeMap attrs = node.getAttributes();
    for (int i = 0; i < attrs.getLength(); i++) {
      Node attr = attrs.item(i);
      if (attr.getLocalName().equals(name)) {
        return attr.getNodeValue();
      }
    }
  }
  return null;
}

代码示例来源:origin: eclipse-color-theme/eclipse-color-theme

private void parseStandardMappings(Element root, Map<String, ColorThemeMapping> mappings) {
  Node mappingsNode = root.getElementsByTagName("mappings").item(0);
  NodeList mappingNodes = mappingsNode.getChildNodes();
  for (int i = 0; i < mappingNodes.getLength(); i++) {
    Node mappingNode = mappingNodes.item(i);
    if (mappingNode.hasAttributes()) {
      String pluginKey = extractAttribute(mappingNode, "pluginKey");
      String themeKey = extractAttribute(mappingNode, "themeKey");
      mappings.put(pluginKey, createMapping(pluginKey, themeKey));
    }
  }
}

代码示例来源:origin: eclipse-color-theme/eclipse-color-theme

private void parseSemanticHighlightingMappings(Element root, Map<String, ColorThemeMapping> mappings) {
  Node mappingsNode = root.getElementsByTagName("semanticHighlightingMappings").item(0);
  if (mappingsNode != null) {
    NodeList mappingNodes = mappingsNode.getChildNodes();
    for (int i = 0; i < mappingNodes.getLength(); i++) {
      Node mappingNode = mappingNodes.item(i);
      if (mappingNode.hasAttributes()) {
        String pluginKey = extractAttribute(mappingNode, "pluginKey");
        String themeKey = extractAttribute(mappingNode, "themeKey");
        mappings.put(pluginKey, createSemanticHighlightingMapping(pluginKey, themeKey));
      }
    }
  }
}

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

/**
 * Add element to priority list examining node attributes: priority (for urls) and type (for checksums)
 */
protected static void addPriorityListElementExaminingNode(String tagName, Node node, List<Pair<String, Integer>> priorityList) {
  Integer priority = Integer.MAX_VALUE;
  String first = node.getTextContent();
  if (node.hasAttributes()) {
    NamedNodeMap attributes = node.getAttributes();
    for (int k=0; k<attributes.getLength(); k++) {
      Node attr = attributes.item(k);
      if (tagName.equals("url") && attr.getNodeName().equals("priority")) {
        String prio = attr.getNodeValue().replace("\"", "");
        priority = Integer.parseInt(prio);
        break;
      } else if (tagName.equals("hash") && attr.getNodeName().equals("type")) {
        first = "{" + attr.getNodeValue() + "}" + first;
        break;
      }
    }
  }
  priorityList.add(new Pair<>(first, priority));
}

代码示例来源:origin: vsch/flexmark-java

static <T> T forAllAttributesUntil(final Node node, final T defaultValue, final String xmlns, final String[] attributeNames, final Function<Node, T> function) {
  if (node.hasAttributes()) {
    final String xmlnsPrefix = xmlnsPrefix(node, xmlns);
    final NamedNodeMap attributes = node.getAttributes();
    int iMax = attributes.getLength();
    for (int i = 0; i < iMax; i++) {
      Node item = attributes.item(i);
      if (attributeNames == null || attributeNames.length == 0) {
        // pass all children
        T result = function.apply(item);
        if (result != null) {
          return result;
        }
      } else {
        for (String attributeName : attributeNames) {
          if (item.getNodeName().equals(xmlnsPrefix + attributeName)) {
            T result = function.apply(item);
            if (result != null) {
              return result;
            }
          }
        }
      }
    }
  }
  return defaultValue;
}

代码示例来源:origin: eclipse-color-theme/eclipse-color-theme

for (int i = 0; i < entryNodes.getLength(); i++) {
  Node entryNode = entryNodes.item(i);
  if (entryNode.hasAttributes()) {
    String color = entryNode.getAttributes().getNamedItem("color")
        .getNodeValue();
  for (int i = 0; i < nodeListEclipseColorThemeMapping.getLength(); ++i) {
    Node eclipseColorThemeMapping = nodeListEclipseColorThemeMapping.item(i);
    if (eclipseColorThemeMapping.hasAttributes()) {
      String pluginId = eclipseColorThemeMapping.getAttributes().getNamedItem("plugin").getNodeValue();
      Map<String, ColorThemeMapping> mapMappings = new HashMap<String, ColorThemeMapping>();

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

ColorMap symbol = factory.createColorMap();
if (root.hasAttributes()) {

代码示例来源:origin: org.apache.tika/tika-parsers

private static String getFirstAttribute(Node node, String ns, String name) {
  if (node.hasAttributes()) {
    NamedNodeMap attrs = node.getAttributes();
    for (int i = 0; i < attrs.getLength(); i++) {
      Node attr = attrs.item(i);
      if (attr.getLocalName().equals(name)) {
        return attr.getNodeValue();
      }
    }
  }
  return null;
}

相关文章