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

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

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

  1. @Override
  2. protected String getBeanClassName(Element element) {
  3. if (element.hasAttribute(WEAVER_CLASS_ATTRIBUTE)) {
  4. return element.getAttribute(WEAVER_CLASS_ATTRIBUTE);
  5. }
  6. return DEFAULT_LOAD_TIME_WEAVER_CLASS_NAME;
  7. }

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

  1. private void readPackageConfigFromXml(Node node) throws IOException {
  2. NodeList childNodes = node.getChildNodes();
  3. if (childNodes.getLength() > 0) {
  4. for (int j = 0, n = childNodes.getLength(); j < n; j++) {
  5. Node child = childNodes.item(j);
  6. if (child.getNodeType() == Node.ELEMENT_NODE) {
  7. Element check = (Element) child;
  8. String tagName = check.getTagName();
  9. String value = check.getAttribute(ATTR_VALUE);
  10. String name = check.getAttribute(ATTR_NAME);
  11. if (tagName.equals(ATTR_CONFIG_FIELD)) {
  12. mPackageFields.put(name, value);
  13. } else {
  14. System.err.println("unknown package config tag " + tagName);
  15. }
  16. }
  17. }
  18. }
  19. }

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

  1. /**
  2. * @param xmlDescription
  3. * xmlDescription
  4. * @throws NullPointerException
  5. * NullPointerException
  6. * @throws MalformedURLException
  7. * MalformedURLException
  8. */
  9. public VoiceComponentDescription(Element xmlDescription) throws NullPointerException, MalformedURLException {
  10. super(xmlDescription);
  11. this.gender = xmlDescription.getAttribute("gender");
  12. this.type = xmlDescription.getAttribute("type");
  13. Element dependsElement = (Element) xmlDescription.getElementsByTagName("depends").item(0);
  14. this.dependsLanguage = dependsElement.getAttribute("language");
  15. this.dependsVersion = dependsElement.getAttribute("version");
  16. }

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

  1. private static void parseProperties(NodeList nodeList, RootBeanDefinition beanDefinition) {
  2. if (nodeList != null && nodeList.getLength() > 0) {
  3. for (int i = 0; i < nodeList.getLength(); i++) {
  4. Node node = nodeList.item(i);
  5. if (node instanceof Element) {
  6. if ("property".equals(node.getNodeName())
  7. || "property".equals(node.getLocalName())) {
  8. String name = ((Element) node).getAttribute("name");
  9. if (name != null && name.length() > 0) {
  10. String value = ((Element) node).getAttribute("value");
  11. String ref = ((Element) node).getAttribute("ref");
  12. if (value != null && value.length() > 0) {
  13. beanDefinition.getPropertyValues().addPropertyValue(name, value);
  14. } else if (ref != null && ref.length() > 0) {
  15. beanDefinition.getPropertyValues().addPropertyValue(name, new RuntimeBeanReference(ref));
  16. } else {
  17. throw new UnsupportedOperationException("Unsupported <property name=\"" + name + "\"> sub tag, Only supported <property name=\"" + name + "\" ref=\"...\" /> or <property name=\"" + name + "\" value=\"...\" />");
  18. }
  19. }
  20. }
  21. }
  22. }
  23. }
  24. }

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

  1. /**
  2. * Parse a list element.
  3. */
  4. public List<Object> parseListElement(Element collectionEle, @Nullable BeanDefinition bd) {
  5. String defaultElementType = collectionEle.getAttribute(VALUE_TYPE_ATTRIBUTE);
  6. NodeList nl = collectionEle.getChildNodes();
  7. ManagedList<Object> target = new ManagedList<>(nl.getLength());
  8. target.setSource(extractSource(collectionEle));
  9. target.setElementTypeName(defaultElementType);
  10. target.setMergeEnabled(parseMergeAttribute(collectionEle));
  11. parseCollectionElements(nl, target, bd, defaultElementType);
  12. return target;
  13. }

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

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

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

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

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

  1. private static Element findPropertyByName(Element bean, String name) {
  2. NodeList propertyList = bean.getElementsByTagName("property");
  3. for (int j = 0, m = propertyList.getLength(); j < m; ++j) {
  4. Node node = propertyList.item(j);
  5. if (node instanceof Element) {
  6. Element p = (Element) node;
  7. if (name.equals(p.getAttribute("name"))) {
  8. return p;
  9. }
  10. }
  11. }
  12. return null;
  13. }

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

  1. private static void parseProperties(NodeList nodeList, RootBeanDefinition beanDefinition) {
  2. if (nodeList != null && nodeList.getLength() > 0) {
  3. for (int i = 0; i < nodeList.getLength(); i++) {
  4. Node node = nodeList.item(i);
  5. if (node instanceof Element) {
  6. if ("property".equals(node.getNodeName())
  7. || "property".equals(node.getLocalName())) {
  8. String name = ((Element) node).getAttribute("name");
  9. if (name != null && name.length() > 0) {
  10. String value = ((Element) node).getAttribute("value");
  11. String ref = ((Element) node).getAttribute("ref");
  12. if (value != null && value.length() > 0) {
  13. beanDefinition.getPropertyValues().addPropertyValue(name, value);
  14. } else if (ref != null && ref.length() > 0) {
  15. beanDefinition.getPropertyValues().addPropertyValue(name, new RuntimeBeanReference(ref));
  16. } else {
  17. throw new UnsupportedOperationException("Unsupported <property name=\"" + name + "\"> sub tag, Only supported <property name=\"" + name + "\" ref=\"...\" /> or <property name=\"" + name + "\" value=\"...\" />");
  18. }
  19. }
  20. }
  21. }
  22. }
  23. }
  24. }

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

  1. /**
  2. * Parse an array element.
  3. */
  4. public Object parseArrayElement(Element arrayEle, @Nullable BeanDefinition bd) {
  5. String elementType = arrayEle.getAttribute(VALUE_TYPE_ATTRIBUTE);
  6. NodeList nl = arrayEle.getChildNodes();
  7. ManagedArray target = new ManagedArray(elementType, nl.getLength());
  8. target.setSource(extractSource(arrayEle));
  9. target.setElementTypeName(elementType);
  10. target.setMergeEnabled(parseMergeAttribute(arrayEle));
  11. parseCollectionElements(nl, target, bd, elementType);
  12. return target;
  13. }

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

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

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

  1. static String extractCacheManager(Element element) {
  2. return (element.hasAttribute(CacheNamespaceHandler.CACHE_MANAGER_ATTRIBUTE) ?
  3. element.getAttribute(CacheNamespaceHandler.CACHE_MANAGER_ATTRIBUTE) :
  4. CacheNamespaceHandler.DEFAULT_CACHE_MANAGER_BEAN_NAME);
  5. }

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

  1. /**
  2. * @param xmlDescription
  3. * xmlDescription
  4. * @throws NullPointerException
  5. * NullPointerException
  6. * @throws MalformedURLException
  7. * MalformedURLException
  8. */
  9. public VoiceComponentDescription(Element xmlDescription) throws NullPointerException, MalformedURLException {
  10. super(xmlDescription);
  11. this.gender = xmlDescription.getAttribute("gender");
  12. this.type = xmlDescription.getAttribute("type");
  13. Element dependsElement = (Element) xmlDescription.getElementsByTagName("depends").item(0);
  14. this.dependsLanguage = dependsElement.getAttribute("language");
  15. this.dependsVersion = dependsElement.getAttribute("version");
  16. }

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

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

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

  1. private void readLibPatternsFromXml(Node node) throws IOException {
  2. NodeList childNodes = node.getChildNodes();
  3. if (childNodes.getLength() > 0) {
  4. for (int j = 0, n = childNodes.getLength(); j < n; j++) {
  5. Node child = childNodes.item(j);
  6. if (child.getNodeType() == Node.ELEMENT_NODE) {
  7. Element check = (Element) child;
  8. String tagName = check.getTagName();
  9. String value = check.getAttribute(ATTR_VALUE);
  10. if (tagName.equals(ATTR_PATTERN)) {
  11. addToPatterns(value, mSoFilePattern);
  12. } else {
  13. System.err.println("unknown dex tag " + tagName);
  14. }
  15. }
  16. }
  17. }
  18. }

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

  1. @SuppressWarnings("unchecked")
  2. private static ManagedMap parseParameters(NodeList nodeList, RootBeanDefinition beanDefinition) {
  3. if (nodeList != null && nodeList.getLength() > 0) {
  4. ManagedMap parameters = null;
  5. for (int i = 0; i < nodeList.getLength(); i++) {
  6. Node node = nodeList.item(i);
  7. if (node instanceof Element) {
  8. if ("parameter".equals(node.getNodeName())
  9. || "parameter".equals(node.getLocalName())) {
  10. if (parameters == null) {
  11. parameters = new ManagedMap();
  12. }
  13. String key = ((Element) node).getAttribute("key");
  14. String value = ((Element) node).getAttribute("value");
  15. boolean hide = "true".equals(((Element) node).getAttribute("hide"));
  16. if (hide) {
  17. key = Constants.HIDE_KEY_PREFIX + key;
  18. }
  19. parameters.put(key, new TypedStringValue(value, String.class));
  20. }
  21. }
  22. }
  23. return parameters;
  24. }
  25. return null;
  26. }

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

  1. /**
  2. * Parse a set element.
  3. */
  4. public Set<Object> parseSetElement(Element collectionEle, @Nullable BeanDefinition bd) {
  5. String defaultElementType = collectionEle.getAttribute(VALUE_TYPE_ATTRIBUTE);
  6. NodeList nl = collectionEle.getChildNodes();
  7. ManagedSet<Object> target = new ManagedSet<>(nl.getLength());
  8. target.setSource(extractSource(collectionEle));
  9. target.setElementTypeName(defaultElementType);
  10. target.setMergeEnabled(parseMergeAttribute(collectionEle));
  11. parseCollectionElements(nl, target, bd, defaultElementType);
  12. return target;
  13. }

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

  1. /**
  2. * Parse the validated document and add entries to the given unit info list.
  3. */
  4. protected List<SpringPersistenceUnitInfo> parseDocument(
  5. Resource resource, Document document, List<SpringPersistenceUnitInfo> infos) throws IOException {
  6. Element persistence = document.getDocumentElement();
  7. String version = persistence.getAttribute(PERSISTENCE_VERSION);
  8. URL rootUrl = determinePersistenceUnitRootUrl(resource);
  9. List<Element> units = DomUtils.getChildElementsByTagName(persistence, PERSISTENCE_UNIT);
  10. for (Element unit : units) {
  11. infos.add(parsePersistenceUnitInfo(unit, version, rootUrl));
  12. }
  13. return infos;
  14. }

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

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

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

  1. @ExpectWarning("RCN_REDUNDANT_NULLCHECK_OF_NONNULL_VALUE")
  2. public String getFirstChildName(Element e) {
  3. NodeList list = e.getElementsByTagName("child");
  4. if(list != null) {
  5. return ((Element)list.item(0)).getAttribute("name");
  6. }
  7. return null;
  8. }
  9. }

相关文章