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

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

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

Element.getAttributeNode介绍

[英]Retrieves an attribute node by name.
To retrieve an attribute node by qualified name and namespace URI, use the getAttributeNodeNS method.
[中]按名称检索属性节点。
要按限定名称和命名空间URI检索属性节点,请使用getAttributeNodeNS方法。

代码示例

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

  1. public static String getAttribute(Element element, String name) {
  2. Attr attr = element.getAttributeNode(name);
  3. return (attr != null)? attr.getValue(): null;
  4. }

代码示例来源:origin: com.thoughtworks.xstream/xstream

  1. public String getAttribute(String name) {
  2. Attr attribute = currentElement.getAttributeNode(encodeAttribute(name));
  3. return attribute == null ? null : attribute.getValue();
  4. }

代码示例来源:origin: simpligility/android-maven-plugin

  1. private void performVersioCodeAutoIncrement( Element manifestElement )
  2. {
  3. Attr versionCode = manifestElement.getAttributeNode( ATTR_VERSION_CODE );
  4. int currentVersionCode = 0;
  5. if ( versionCode != null )
  6. {
  7. currentVersionCode = NumberUtils.toInt( versionCode.getValue(), 0 );
  8. }
  9. currentVersionCode++;
  10. manifestElement.setAttribute( ATTR_VERSION_CODE, String.valueOf( currentVersionCode ) );
  11. project.getProperties().setProperty( "android.manifest.versionCode", String.valueOf( currentVersionCode ) );
  12. }

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

  1. Attr att = elem.getAttributeNode(attName);
  2. value = att.getValue();

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

  1. Attr att = elem.getAttributeNode(attName);
  2. value = att.getValue();

代码示例来源:origin: simpligility/android-maven-plugin

  1. private boolean updateApplicationAttribute( Element manifestElement,
  2. String attribute, String value, boolean dirty )
  3. {
  4. NodeList appElements =
  5. manifestElement.getElementsByTagName( ELEM_APPLICATION );
  6. // Update all application nodes. Not sure whether there will ever be
  7. // more than one.
  8. for ( int i = 0; i < appElements.getLength(); ++i )
  9. {
  10. Node node = appElements.item( i );
  11. getLog().info( "Testing if node " + node.getNodeName()
  12. + " is application" );
  13. if ( node.getNodeType() == Node.ELEMENT_NODE )
  14. {
  15. Element element = (Element) node;
  16. Attr labelAttrib = element.getAttributeNode( attribute );
  17. if ( labelAttrib == null
  18. || !value.equals( labelAttrib.getValue() ) )
  19. {
  20. getLog().info( "Setting " + attribute + " to " + value );
  21. element.setAttribute( attribute, String.valueOf( value ) );
  22. dirty = true;
  23. }
  24. }
  25. }
  26. return dirty;
  27. }

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

  1. if (n instanceof Element && n.getNodeName().contains("String")) {
  2. strings.add(((Element) n).getAttributeNode("value").getValue());

代码示例来源:origin: simpligility/android-maven-plugin

  1. Attr providerName = providerElem.getAttributeNode( ATTR_NAME );
  2. getLog().debug( "Checking provider " + providerName.getValue() );
  3. if ( shouldPerformProviderUpdate( providerName ) )
  4. String name = providerName.getValue();
  5. String newAuthorities = parsedProviderAuthorities.getProperty( name );
  6. getLog().info( "Updating provider " + name + " authorities attr to " + newAuthorities );

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

  1. Element sharedPoolElement = (Element)item;
  2. String poolName = sharedPoolElement.getAttribute("name"); // required
  3. Attr fromAttr = sharedPoolElement.getAttributeNode("from"); // optional
  4. String fromResource = (fromAttr == null ? null : fromAttr.getValue());
  5. Attr unitAttr = sharedPoolElement.getAttributeNode("unit"); // optional - default 'B'
  6. String unit = (unitAttr == null ? "B" : unitAttr.getValue());
  7. MemoryUnit memoryUnit = MemoryUnit.valueOf(unit.toUpperCase(Locale.ENGLISH));

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

  1. final Attr fromAttr = fragment.getAttributeNode("from");
  2. final String from = (fromAttr == null ? null : fromAttr.getValue());

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

  1. final Attr urlAttribute = ((Element)item).getAttributeNode("url");
  2. final String urlValue = urlAttribute.getValue();
  3. try {
  4. connectionUri = new URI(urlValue);
  5. for (int j = 0; j < serverNodes.getLength(); j++) {
  6. final Node serverNode = serverNodes.item(j);
  7. final String host = ((Element)serverNode).getAttributeNode("host").getValue();
  8. final Attr port = ((Element)serverNode).getAttributeNode("port");
  9. InetSocketAddress address;
  10. if (port == null) {
  11. address = InetSocketAddress.createUnresolved(host, 0);
  12. } else {
  13. String portString = port.getValue();
  14. address = InetSocketAddress.createUnresolved(host, Integer.parseInt(portString));

代码示例来源:origin: simpligility/android-maven-plugin

  1. Attr versionNameAttrib = manifestElement.getAttributeNode( ATTR_VERSION_NAME );
  2. if ( versionNameAttrib == null || ! StringUtils.equals( parsedVersionName, versionNameAttrib.getValue() ) )
  3. Attr versionCodeAttr = manifestElement.getAttributeNode( ATTR_VERSION_CODE );
  4. int currentVersionCode = 0;
  5. if ( versionCodeAttr != null )
  6. currentVersionCode = NumberUtils.toInt( versionCodeAttr.getValue(), 0 );
  7. Attr sharedUserIdAttrib = manifestElement.getAttributeNode( ATTR_SHARED_USER_ID );
  8. .equals( parsedSharedUserId, sharedUserIdAttrib.getValue() ) )
  9. Attr debuggableAttrib = element.getAttributeNode( ATTR_DEBUGGABLE );
  10. if ( debuggableAttrib == null || parsedDebuggable != BooleanUtils
  11. .toBoolean( debuggableAttrib.getValue() ) )

代码示例来源:origin: kiegroup/jbpm

  1. Node node = (Node) parser.getCurrent();
  2. String attachedTo = element.getAttribute("attachedToRef");
  3. Attr cancelActivityAttr = element.getAttributeNode("cancelActivity");
  4. boolean cancelActivity = Boolean.parseBoolean(cancelActivityAttr.getValue());

代码示例来源:origin: org.apache.poi/poi-ooxml

  1. Attr targetModeAttr = element.getAttributeNode(PackageRelationship.TARGET_MODE_ATTRIBUTE_NAME);
  2. TargetMode targetMode = TargetMode.INTERNAL;
  3. if (targetModeAttr != null) {
  4. targetMode = targetModeAttr.getValue().toLowerCase(Locale.ROOT)
  5. .equals("internal") ? TargetMode.INTERNAL
  6. : TargetMode.EXTERNAL;

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

  1. /**
  2. * Ensures the namespace declared by {@link ClusteringCacheManagerServiceConfigurationParser} and its
  3. * schema are the same.
  4. */
  5. @Test
  6. public void testSchema() throws Exception {
  7. final ClusteringCacheManagerServiceConfigurationParser parser = new ClusteringCacheManagerServiceConfigurationParser();
  8. final StreamSource schemaSource = (StreamSource) parser.getXmlSchema();
  9. final DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
  10. factory.setNamespaceAware(true);
  11. factory.setIgnoringComments(true);
  12. factory.setIgnoringElementContentWhitespace(true);
  13. final DocumentBuilder domBuilder = factory.newDocumentBuilder();
  14. final Element schema = domBuilder.parse(schemaSource.getInputStream()).getDocumentElement();
  15. final Attr targetNamespaceAttr = schema.getAttributeNode("targetNamespace");
  16. assertThat(targetNamespaceAttr, is(not(nullValue())));
  17. assertThat(targetNamespaceAttr.getValue(), is(parser.getNamespace().toString()));
  18. }

代码示例来源:origin: pentaho/mondrian

  1. /**
  2. * This is used to get a Document's namespace attribute value.
  3. *
  4. */
  5. public static String getNamespaceAttributeValue(Document doc) {
  6. Element el = doc.getDocumentElement();
  7. String prefix = el.getPrefix();
  8. Attr attr = (prefix == null)
  9. ? el.getAttributeNode(XMLNS)
  10. : el.getAttributeNode(XMLNS + ':' + prefix);
  11. return (attr == null) ? null : attr.getValue();
  12. }

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

  1. private static void renameNodeReference(List<Element> elements, String attributeName, String oldNodeName, String newNodeName) {
  2. for (Element c : elements) {
  3. Attr nodeRef = c.getAttributeNode(attributeName);
  4. String nodeName = nodeRef.getValue();
  5. if (oldNodeName.equals(nodeName)) {
  6. nodeRef.setValue(newNodeName);
  7. }
  8. }
  9. }

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

  1. /**
  2. * Returns the value of an attribute of an element. Returns null
  3. * if the attribute is not found (whereas Element.getAttribute
  4. * returns "" if an attrib is not found). This method should be
  5. * used for elements that support extension attributes because it
  6. * does not track unexpected attributes.
  7. *
  8. * @param el Element whose attrib is looked for
  9. * @param attrName name of attribute to look for
  10. * @return the attribute value
  11. */
  12. static public String getAttribute (Element el, String attrName) {
  13. String sRet = null;
  14. Attr attr = el.getAttributeNode(attrName);
  15. if (attr != null) {
  16. sRet = attr.getValue();
  17. }
  18. return sRet;
  19. }

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

  1. private static boolean isNodeWithPrototype(Element e, String nodePrototype) {
  2. if (e.getTagName().equals("node")) {
  3. Attr prototype = e.getAttributeNode("prototype");
  4. if (prototype != null && prototype.getValue().equals(nodePrototype)) {
  5. return true;
  6. }
  7. }
  8. return false;
  9. }

代码示例来源:origin: mulesoft/mule

  1. private void addSchemaLocationIfNeeded(String namespaceURI, String schemaLocation) {
  2. Attr schemaLocationAttribute = doc.getDocumentElement().getAttributeNode("xsi:schemaLocation");
  3. if (schemaLocationAttribute != null && !schemaLocationAttribute.getValue().contains(namespaceURI)) {
  4. doc.getDocumentElement().setAttributeNS("http://www.w3.org/2001/XMLSchema-instance",
  5. "xsi:schemaLocation",
  6. schemaLocationAttribute.getValue() + " " + namespaceURI + " " + schemaLocation);
  7. }
  8. }

相关文章