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

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

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

Element.getAttribute介绍

[英]Retrieves an attribute value by name.
[中]按名称检索属性值。

代码示例

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

@Override
protected String getBeanClassName(Element element) {
  if (element.hasAttribute(WEAVER_CLASS_ATTRIBUTE)) {
    return element.getAttribute(WEAVER_CLASS_ATTRIBUTE);
  }
  return DEFAULT_LOAD_TIME_WEAVER_CLASS_NAME;
}

代码示例来源:origin: Tencent/tinker

private void readPackageConfigFromXml(Node node) throws IOException {
  NodeList childNodes = node.getChildNodes();
  if (childNodes.getLength() > 0) {
    for (int j = 0, n = childNodes.getLength(); j < n; j++) {
      Node child = childNodes.item(j);
      if (child.getNodeType() == Node.ELEMENT_NODE) {
        Element check = (Element) child;
        String tagName = check.getTagName();
        String value = check.getAttribute(ATTR_VALUE);
        String name = check.getAttribute(ATTR_NAME);
        if (tagName.equals(ATTR_CONFIG_FIELD)) {
          mPackageFields.put(name, value);
        } else {
          System.err.println("unknown package config tag " + tagName);
        }
      }
    }
  }
}

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

/**
 * @param xmlDescription
 *            xmlDescription
 * @throws NullPointerException
 *             NullPointerException
 * @throws MalformedURLException
 *             MalformedURLException
 */
public VoiceComponentDescription(Element xmlDescription) throws NullPointerException, MalformedURLException {
  super(xmlDescription);
  this.gender = xmlDescription.getAttribute("gender");
  this.type = xmlDescription.getAttribute("type");
  Element dependsElement = (Element) xmlDescription.getElementsByTagName("depends").item(0);
  this.dependsLanguage = dependsElement.getAttribute("language");
  this.dependsVersion = dependsElement.getAttribute("version");
}

代码示例来源:origin: apache/incubator-dubbo

private static void parseProperties(NodeList nodeList, RootBeanDefinition beanDefinition) {
  if (nodeList != null && nodeList.getLength() > 0) {
    for (int i = 0; i < nodeList.getLength(); i++) {
      Node node = nodeList.item(i);
      if (node instanceof Element) {
        if ("property".equals(node.getNodeName())
            || "property".equals(node.getLocalName())) {
          String name = ((Element) node).getAttribute("name");
          if (name != null && name.length() > 0) {
            String value = ((Element) node).getAttribute("value");
            String ref = ((Element) node).getAttribute("ref");
            if (value != null && value.length() > 0) {
              beanDefinition.getPropertyValues().addPropertyValue(name, value);
            } else if (ref != null && ref.length() > 0) {
              beanDefinition.getPropertyValues().addPropertyValue(name, new RuntimeBeanReference(ref));
            } else {
              throw new UnsupportedOperationException("Unsupported <property name=\"" + name + "\"> sub tag, Only supported <property name=\"" + name + "\" ref=\"...\" /> or <property name=\"" + name + "\" value=\"...\" />");
            }
          }
        }
      }
    }
  }
}

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

/**
 * Parse a list element.
 */
public List<Object> parseListElement(Element collectionEle, @Nullable BeanDefinition bd) {
  String defaultElementType = collectionEle.getAttribute(VALUE_TYPE_ATTRIBUTE);
  NodeList nl = collectionEle.getChildNodes();
  ManagedList<Object> target = new ManagedList<>(nl.getLength());
  target.setSource(extractSource(collectionEle));
  target.setElementTypeName(defaultElementType);
  target.setMergeEnabled(parseMergeAttribute(collectionEle));
  parseCollectionElements(nl, target, bd, defaultElementType);
  return target;
}

代码示例来源:origin: sannies/mp4parser

public static String getLanguage(Document document) {
  return document.getDocumentElement().getAttribute("xml:lang");
}

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

/**
 * Try to determine the locale of a document by looking at the xml:lang attribute of the document element.
 * 
 * @param doc
 *            the document in which to look for a locale.
 * @return the locale set for the document, or null if no locale is set.
 */
public static Locale getLocale(Document doc) {
  if (doc.getDocumentElement().hasAttribute("xml:lang"))
    return MaryUtils.string2locale(doc.getDocumentElement().getAttribute("xml:lang"));
  return null;
}

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

private static Element findPropertyByName(Element bean, String name) {
  NodeList propertyList = bean.getElementsByTagName("property");
  for (int j = 0, m = propertyList.getLength(); j < m; ++j) {
    Node node = propertyList.item(j);
    if (node instanceof Element) {
      Element p = (Element) node;
      if (name.equals(p.getAttribute("name"))) {
        return p;
      }
    }
  }
  return null;
}

代码示例来源:origin: apache/incubator-dubbo

private static void parseProperties(NodeList nodeList, RootBeanDefinition beanDefinition) {
  if (nodeList != null && nodeList.getLength() > 0) {
    for (int i = 0; i < nodeList.getLength(); i++) {
      Node node = nodeList.item(i);
      if (node instanceof Element) {
        if ("property".equals(node.getNodeName())
            || "property".equals(node.getLocalName())) {
          String name = ((Element) node).getAttribute("name");
          if (name != null && name.length() > 0) {
            String value = ((Element) node).getAttribute("value");
            String ref = ((Element) node).getAttribute("ref");
            if (value != null && value.length() > 0) {
              beanDefinition.getPropertyValues().addPropertyValue(name, value);
            } else if (ref != null && ref.length() > 0) {
              beanDefinition.getPropertyValues().addPropertyValue(name, new RuntimeBeanReference(ref));
            } else {
              throw new UnsupportedOperationException("Unsupported <property name=\"" + name + "\"> sub tag, Only supported <property name=\"" + name + "\" ref=\"...\" /> or <property name=\"" + name + "\" value=\"...\" />");
            }
          }
        }
      }
    }
  }
}

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

/**
 * Parse an array element.
 */
public Object parseArrayElement(Element arrayEle, @Nullable BeanDefinition bd) {
  String elementType = arrayEle.getAttribute(VALUE_TYPE_ATTRIBUTE);
  NodeList nl = arrayEle.getChildNodes();
  ManagedArray target = new ManagedArray(elementType, nl.getLength());
  target.setSource(extractSource(arrayEle));
  target.setElementTypeName(elementType);
  target.setMergeEnabled(parseMergeAttribute(arrayEle));
  parseCollectionElements(nl, target, bd, elementType);
  return target;
}

代码示例来源:origin: jMonkeyEngine/jmonkeyengine

public DOMInputCapsule(Document doc, XMLImporter importer) {
  this.doc = doc;
  this.importer = importer;
  currentElem = doc.getDocumentElement();
  
  String version = currentElem.getAttribute("format_version");
  importer.formatVersion = version.equals("") ? 0 : Integer.parseInt(version);
}

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

static String extractCacheManager(Element element) {
  return (element.hasAttribute(CacheNamespaceHandler.CACHE_MANAGER_ATTRIBUTE) ?
      element.getAttribute(CacheNamespaceHandler.CACHE_MANAGER_ATTRIBUTE) :
      CacheNamespaceHandler.DEFAULT_CACHE_MANAGER_BEAN_NAME);
}

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

/**
 * @param xmlDescription
 *            xmlDescription
 * @throws NullPointerException
 *             NullPointerException
 * @throws MalformedURLException
 *             MalformedURLException
 */
public VoiceComponentDescription(Element xmlDescription) throws NullPointerException, MalformedURLException {
  super(xmlDescription);
  this.gender = xmlDescription.getAttribute("gender");
  this.type = xmlDescription.getAttribute("type");
  Element dependsElement = (Element) xmlDescription.getElementsByTagName("depends").item(0);
  this.dependsLanguage = dependsElement.getAttribute("language");
  this.dependsVersion = dependsElement.getAttribute("version");
}

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

/**
 * Try to determine the locale of a document by looking at the xml:lang attribute of the document element.
 * 
 * @param doc
 *            the document in which to look for a locale.
 * @return the locale set for the document, or null if no locale is set.
 */
public static Locale getLocale(Document doc) {
  if (doc.getDocumentElement().hasAttribute("xml:lang"))
    return MaryUtils.string2locale(doc.getDocumentElement().getAttribute("xml:lang"));
  return null;
}

代码示例来源:origin: Tencent/tinker

private void readLibPatternsFromXml(Node node) throws IOException {
  NodeList childNodes = node.getChildNodes();
  if (childNodes.getLength() > 0) {
    for (int j = 0, n = childNodes.getLength(); j < n; j++) {
      Node child = childNodes.item(j);
      if (child.getNodeType() == Node.ELEMENT_NODE) {
        Element check = (Element) child;
        String tagName = check.getTagName();
        String value = check.getAttribute(ATTR_VALUE);
        if (tagName.equals(ATTR_PATTERN)) {
          addToPatterns(value, mSoFilePattern);
        } else {
          System.err.println("unknown dex tag " + tagName);
        }
      }
    }
  }
}

代码示例来源:origin: apache/incubator-dubbo

@SuppressWarnings("unchecked")
private static ManagedMap parseParameters(NodeList nodeList, RootBeanDefinition beanDefinition) {
  if (nodeList != null && nodeList.getLength() > 0) {
    ManagedMap parameters = null;
    for (int i = 0; i < nodeList.getLength(); i++) {
      Node node = nodeList.item(i);
      if (node instanceof Element) {
        if ("parameter".equals(node.getNodeName())
            || "parameter".equals(node.getLocalName())) {
          if (parameters == null) {
            parameters = new ManagedMap();
          }
          String key = ((Element) node).getAttribute("key");
          String value = ((Element) node).getAttribute("value");
          boolean hide = "true".equals(((Element) node).getAttribute("hide"));
          if (hide) {
            key = Constants.HIDE_KEY_PREFIX + key;
          }
          parameters.put(key, new TypedStringValue(value, String.class));
        }
      }
    }
    return parameters;
  }
  return null;
}

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

/**
 * Parse a set element.
 */
public Set<Object> parseSetElement(Element collectionEle, @Nullable BeanDefinition bd) {
  String defaultElementType = collectionEle.getAttribute(VALUE_TYPE_ATTRIBUTE);
  NodeList nl = collectionEle.getChildNodes();
  ManagedSet<Object> target = new ManagedSet<>(nl.getLength());
  target.setSource(extractSource(collectionEle));
  target.setElementTypeName(defaultElementType);
  target.setMergeEnabled(parseMergeAttribute(collectionEle));
  parseCollectionElements(nl, target, bd, defaultElementType);
  return target;
}

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

/**
 * Parse the validated document and add entries to the given unit info list.
 */
protected List<SpringPersistenceUnitInfo> parseDocument(
    Resource resource, Document document, List<SpringPersistenceUnitInfo> infos) throws IOException {
  Element persistence = document.getDocumentElement();
  String version = persistence.getAttribute(PERSISTENCE_VERSION);
  URL rootUrl = determinePersistenceUnitRootUrl(resource);
  List<Element> units = DomUtils.getChildElementsByTagName(persistence, PERSISTENCE_UNIT);
  for (Element unit : units) {
    infos.add(parsePersistenceUnitInfo(unit, version, rootUrl));
  }
  return infos;
}

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

static String getTransactionManagerName(Element element) {
  return (element.hasAttribute(TRANSACTION_MANAGER_ATTRIBUTE) ?
      element.getAttribute(TRANSACTION_MANAGER_ATTRIBUTE) : DEFAULT_TRANSACTION_MANAGER_BEAN_NAME);
}

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

@ExpectWarning("RCN_REDUNDANT_NULLCHECK_OF_NONNULL_VALUE")
  public String getFirstChildName(Element e) {
    NodeList list = e.getElementsByTagName("child");
    if(list != null) {
      return ((Element)list.item(0)).getAttribute("name");
    }
    return null;
  }
}

相关文章

微信公众号

最新文章

更多