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

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

本文整理了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

  1. @Override
  2. public boolean hasAttributes() {
  3. return node.hasAttributes();
  4. }

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

  1. /**
  2. * @see org.w3c.dom.Node#hasAttributes()
  3. */
  4. public boolean hasAttributes() {
  5. return m_attributeNode.hasAttributes();
  6. }

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

  1. private void parseAttrList(NodeList nodeList) {
  2. for (int count = 0; count < nodeList.getLength(); count++) {
  3. Node tempNode = nodeList.item(count);
  4. if (tempNode.getNodeType() == Node.ELEMENT_NODE
  5. && tempNode.hasAttributes()
  6. && tempNode.hasChildNodes()) {
  7. String name = null;
  8. NamedNodeMap nodeMap = tempNode.getAttributes();
  9. for (int i = 0; i < nodeMap.getLength(); i++) {
  10. Node node = nodeMap.item(i);
  11. if (node.getNodeName().equals("name")) {
  12. name = node.getNodeValue();
  13. break;
  14. }
  15. }
  16. if (name != null && tempNode.getNodeName().equals("attr")) {
  17. parseValues(name, tempNode.getChildNodes());
  18. } else {
  19. parseAttrList(tempNode.getChildNodes());
  20. }
  21. }
  22. }
  23. }

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

  1. /**
  2. * Climb through <code>node</code>'s ancestors, looking for one with an attribute named <code>attributeName</code>,
  3. * irrespective of the respective <code>ancestorName</code>, and return the attribute's value
  4. *
  5. * @param node
  6. * node
  7. * @param attributeName
  8. * attributeName
  9. * @return value of attribute from closest ancestor with that attribute, or the empty string if no ancestor has that
  10. * attribute.
  11. *
  12. */
  13. public static String getAttributeFromClosestAncestorOfAnyKind(Node node, String attributeName) {
  14. Node parentNode;
  15. while (node != null && (parentNode = node.getParentNode()) != null) {
  16. if (parentNode.hasAttributes()) {
  17. Element parentElement = (Element) parentNode;
  18. if (parentElement.hasAttribute(attributeName)) {
  19. return parentElement.getAttribute(attributeName);
  20. }
  21. }
  22. node = parentNode;
  23. }
  24. return "";
  25. }

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

  1. private void removeEmptyNodes( NodeList nodes ) {
  2. for ( int i = 0; i < nodes.getLength(); i++ ) {
  3. Node node = nodes.item( i );
  4. // Process the tree bottom-up
  5. if ( node.hasChildNodes() ) {
  6. removeEmptyNodes( node.getChildNodes() );
  7. }
  8. boolean nodeIsEmpty =
  9. node.getNodeType() == Node.ELEMENT_NODE && !node.hasAttributes() && !node.hasChildNodes()
  10. && node.getTextContent().length() == 0;
  11. if ( nodeIsEmpty ) {
  12. // We shifted elements left, do not increment counter
  13. node.getParentNode().removeChild( node );
  14. i--;
  15. }
  16. }
  17. }
  18. }

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

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

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

  1. /**
  2. * Climb through <code>node</code>'s ancestors, looking for one with an attribute named <code>attributeName</code>,
  3. * irrespective of the respective <code>ancestorName</code>, and return the attribute's value
  4. *
  5. * @param node
  6. * node
  7. * @param attributeName
  8. * attributeName
  9. * @return value of attribute from closest ancestor with that attribute, or the empty string if no ancestor has that
  10. * attribute.
  11. *
  12. */
  13. public static String getAttributeFromClosestAncestorOfAnyKind(Node node, String attributeName) {
  14. Node parentNode;
  15. while (node != null && (parentNode = node.getParentNode()) != null) {
  16. if (parentNode.hasAttributes()) {
  17. Element parentElement = (Element) parentNode;
  18. if (parentElement.hasAttribute(attributeName)) {
  19. return parentElement.getAttribute(attributeName);
  20. }
  21. }
  22. node = parentNode;
  23. }
  24. return "";
  25. }

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

  1. public List<Object[]> getParameters(Element element) {
  2. List<Object[]> allParameters = Lists.newArrayList();
  3. if (m_onElement != null) {
  4. List<Object> result = Lists.newArrayList();
  5. for (String attributeName : m_onElement.attributes()) {
  6. result.add(element.getAttribute(attributeName));
  7. }
  8. allParameters.add(result.toArray());
  9. } else if (m_tag != null) {
  10. List<Object> result = Lists.newArrayList();
  11. result.add(m_bean);
  12. allParameters.add(result.toArray());
  13. } else {
  14. NodeList childNodes = element.getChildNodes();
  15. for (int i = 0; i < childNodes.getLength(); i++) {
  16. if (childNodes.item(i).hasAttributes()) {
  17. Element item = (Element) childNodes.item(i);
  18. List<Object> result = Lists.newArrayList();
  19. for (String attributeName : m_onElementList.attributes()) {
  20. result.add(item.getAttribute(attributeName));
  21. }
  22. allParameters.add(result.toArray());
  23. }
  24. }
  25. }
  26. return allParameters;
  27. }
  28. }

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

  1. public List<Object[]> getParameters(Element element) {
  2. List<Object[]> allParameters = Lists.newArrayList();
  3. if (m_onElement != null) {
  4. List<Object> result = Lists.newArrayList();
  5. for (String attributeName : m_onElement.attributes()) {
  6. result.add(element.getAttribute(attributeName));
  7. }
  8. allParameters.add(result.toArray());
  9. } else if (m_tag != null) {
  10. List<Object> result = Lists.newArrayList();
  11. result.add(m_bean);
  12. allParameters.add(result.toArray());
  13. } else {
  14. NodeList childNodes = element.getChildNodes();
  15. for (int i = 0; i < childNodes.getLength(); i++) {
  16. if (childNodes.item(i).hasAttributes()) {
  17. Element item = (Element) childNodes.item(i);
  18. List<Object> result = Lists.newArrayList();
  19. for (String attributeName : m_onElementList.attributes()) {
  20. result.add(item.getAttribute(attributeName));
  21. }
  22. allParameters.add(result.toArray());
  23. }
  24. }
  25. }
  26. return allParameters;
  27. }
  28. }

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

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

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

  1. if (node.hasAttributes()) {
  2. if (node.getNodeType() == Node.ELEMENT_NODE
  3. && semanticAttributes
  4. && node.hasAttributes()
  5. && (node.getAttributes().getNamedItem(VALUE) != null
  6. || node.getAttributes().getNamedItem(LOCATION) != null

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

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

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

  1. private static String getFirstAttribute(Node node, String ns, String name) {
  2. if (node.hasAttributes()) {
  3. NamedNodeMap attrs = node.getAttributes();
  4. for (int i = 0; i < attrs.getLength(); i++) {
  5. Node attr = attrs.item(i);
  6. if (attr.getLocalName().equals(name)) {
  7. return attr.getNodeValue();
  8. }
  9. }
  10. }
  11. return null;
  12. }

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

  1. private void parseStandardMappings(Element root, Map<String, ColorThemeMapping> mappings) {
  2. Node mappingsNode = root.getElementsByTagName("mappings").item(0);
  3. NodeList mappingNodes = mappingsNode.getChildNodes();
  4. for (int i = 0; i < mappingNodes.getLength(); i++) {
  5. Node mappingNode = mappingNodes.item(i);
  6. if (mappingNode.hasAttributes()) {
  7. String pluginKey = extractAttribute(mappingNode, "pluginKey");
  8. String themeKey = extractAttribute(mappingNode, "themeKey");
  9. mappings.put(pluginKey, createMapping(pluginKey, themeKey));
  10. }
  11. }
  12. }

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

  1. private void parseSemanticHighlightingMappings(Element root, Map<String, ColorThemeMapping> mappings) {
  2. Node mappingsNode = root.getElementsByTagName("semanticHighlightingMappings").item(0);
  3. if (mappingsNode != null) {
  4. NodeList mappingNodes = mappingsNode.getChildNodes();
  5. for (int i = 0; i < mappingNodes.getLength(); i++) {
  6. Node mappingNode = mappingNodes.item(i);
  7. if (mappingNode.hasAttributes()) {
  8. String pluginKey = extractAttribute(mappingNode, "pluginKey");
  9. String themeKey = extractAttribute(mappingNode, "themeKey");
  10. mappings.put(pluginKey, createSemanticHighlightingMapping(pluginKey, themeKey));
  11. }
  12. }
  13. }
  14. }

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

  1. /**
  2. * Add element to priority list examining node attributes: priority (for urls) and type (for checksums)
  3. */
  4. protected static void addPriorityListElementExaminingNode(String tagName, Node node, List<Pair<String, Integer>> priorityList) {
  5. Integer priority = Integer.MAX_VALUE;
  6. String first = node.getTextContent();
  7. if (node.hasAttributes()) {
  8. NamedNodeMap attributes = node.getAttributes();
  9. for (int k=0; k<attributes.getLength(); k++) {
  10. Node attr = attributes.item(k);
  11. if (tagName.equals("url") && attr.getNodeName().equals("priority")) {
  12. String prio = attr.getNodeValue().replace("\"", "");
  13. priority = Integer.parseInt(prio);
  14. break;
  15. } else if (tagName.equals("hash") && attr.getNodeName().equals("type")) {
  16. first = "{" + attr.getNodeValue() + "}" + first;
  17. break;
  18. }
  19. }
  20. }
  21. priorityList.add(new Pair<>(first, priority));
  22. }

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

  1. static <T> T forAllAttributesUntil(final Node node, final T defaultValue, final String xmlns, final String[] attributeNames, final Function<Node, T> function) {
  2. if (node.hasAttributes()) {
  3. final String xmlnsPrefix = xmlnsPrefix(node, xmlns);
  4. final NamedNodeMap attributes = node.getAttributes();
  5. int iMax = attributes.getLength();
  6. for (int i = 0; i < iMax; i++) {
  7. Node item = attributes.item(i);
  8. if (attributeNames == null || attributeNames.length == 0) {
  9. // pass all children
  10. T result = function.apply(item);
  11. if (result != null) {
  12. return result;
  13. }
  14. } else {
  15. for (String attributeName : attributeNames) {
  16. if (item.getNodeName().equals(xmlnsPrefix + attributeName)) {
  17. T result = function.apply(item);
  18. if (result != null) {
  19. return result;
  20. }
  21. }
  22. }
  23. }
  24. }
  25. }
  26. return defaultValue;
  27. }

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

  1. for (int i = 0; i < entryNodes.getLength(); i++) {
  2. Node entryNode = entryNodes.item(i);
  3. if (entryNode.hasAttributes()) {
  4. String color = entryNode.getAttributes().getNamedItem("color")
  5. .getNodeValue();
  6. for (int i = 0; i < nodeListEclipseColorThemeMapping.getLength(); ++i) {
  7. Node eclipseColorThemeMapping = nodeListEclipseColorThemeMapping.item(i);
  8. if (eclipseColorThemeMapping.hasAttributes()) {
  9. String pluginId = eclipseColorThemeMapping.getAttributes().getNamedItem("plugin").getNodeValue();
  10. Map<String, ColorThemeMapping> mapMappings = new HashMap<String, ColorThemeMapping>();

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

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

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

  1. private static String getFirstAttribute(Node node, String ns, String name) {
  2. if (node.hasAttributes()) {
  3. NamedNodeMap attrs = node.getAttributes();
  4. for (int i = 0; i < attrs.getLength(); i++) {
  5. Node attr = attrs.item(i);
  6. if (attr.getLocalName().equals(name)) {
  7. return attr.getNodeValue();
  8. }
  9. }
  10. }
  11. return null;
  12. }

相关文章