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

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

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

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

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

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

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

private void performVersioCodeAutoIncrement( Element manifestElement )
{
  Attr versionCode = manifestElement.getAttributeNode( ATTR_VERSION_CODE );
  int currentVersionCode = 0;
  if ( versionCode != null )
  {
    currentVersionCode = NumberUtils.toInt( versionCode.getValue(), 0 );
  }
  currentVersionCode++;
  manifestElement.setAttribute( ATTR_VERSION_CODE, String.valueOf( currentVersionCode ) );
  project.getProperties().setProperty( "android.manifest.versionCode", String.valueOf( currentVersionCode ) );
}

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

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

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

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

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

private boolean updateApplicationAttribute( Element manifestElement, 
    String attribute, String value, boolean dirty )
{
  NodeList appElements = 
      manifestElement.getElementsByTagName( ELEM_APPLICATION );
  // Update all application nodes. Not sure whether there will ever be
  // more than one.
  for ( int i = 0; i < appElements.getLength(); ++i )
  {
    Node node = appElements.item( i );
    getLog().info( "Testing if node " + node.getNodeName() 
        + " is application" );
    if ( node.getNodeType() == Node.ELEMENT_NODE )
    {
      Element element = (Element) node;
      Attr labelAttrib = element.getAttributeNode( attribute );
      if ( labelAttrib == null 
          || !value.equals( labelAttrib.getValue() ) )
      {
        getLog().info( "Setting " + attribute + " to " + value );
        element.setAttribute( attribute, String.valueOf( value ) );
        dirty = true;
      }
    }
  }
  return dirty;
}

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

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

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

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

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

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

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

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

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

final Attr urlAttribute = ((Element)item).getAttributeNode("url");
final String urlValue = urlAttribute.getValue();
try {
 connectionUri = new URI(urlValue);
for (int j = 0; j < serverNodes.getLength(); j++) {
 final Node serverNode = serverNodes.item(j);
 final String host = ((Element)serverNode).getAttributeNode("host").getValue();
 final Attr port = ((Element)serverNode).getAttributeNode("port");
 InetSocketAddress address;
 if (port == null) {
  address = InetSocketAddress.createUnresolved(host, 0);
 } else {
  String portString = port.getValue();
  address = InetSocketAddress.createUnresolved(host, Integer.parseInt(portString));

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

Attr versionNameAttrib = manifestElement.getAttributeNode( ATTR_VERSION_NAME );
if ( versionNameAttrib == null || ! StringUtils.equals( parsedVersionName, versionNameAttrib.getValue() ) )
  Attr versionCodeAttr = manifestElement.getAttributeNode( ATTR_VERSION_CODE );
  int currentVersionCode = 0;
  if ( versionCodeAttr != null )
    currentVersionCode = NumberUtils.toInt( versionCodeAttr.getValue(), 0 );
  Attr sharedUserIdAttrib = manifestElement.getAttributeNode( ATTR_SHARED_USER_ID );
      .equals( parsedSharedUserId, sharedUserIdAttrib.getValue() ) )
      Attr debuggableAttrib = element.getAttributeNode( ATTR_DEBUGGABLE );
      if ( debuggableAttrib == null || parsedDebuggable != BooleanUtils
          .toBoolean( debuggableAttrib.getValue() ) )

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

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

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

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

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

/**
 * Ensures the namespace declared by {@link ClusteringCacheManagerServiceConfigurationParser} and its
 * schema are the same.
 */
@Test
public void testSchema() throws Exception {
 final ClusteringCacheManagerServiceConfigurationParser parser = new ClusteringCacheManagerServiceConfigurationParser();
 final StreamSource schemaSource = (StreamSource) parser.getXmlSchema();
 final DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
 factory.setNamespaceAware(true);
 factory.setIgnoringComments(true);
 factory.setIgnoringElementContentWhitespace(true);
 final DocumentBuilder domBuilder = factory.newDocumentBuilder();
 final Element schema = domBuilder.parse(schemaSource.getInputStream()).getDocumentElement();
 final Attr targetNamespaceAttr = schema.getAttributeNode("targetNamespace");
 assertThat(targetNamespaceAttr, is(not(nullValue())));
 assertThat(targetNamespaceAttr.getValue(), is(parser.getNamespace().toString()));
}

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

/**
 * This is used to get a Document's namespace attribute value.
 *
 */
public static String getNamespaceAttributeValue(Document doc) {
  Element el = doc.getDocumentElement();
  String prefix = el.getPrefix();
  Attr attr = (prefix == null)
        ? el.getAttributeNode(XMLNS)
        : el.getAttributeNode(XMLNS + ':' + prefix);
  return (attr == null) ? null : attr.getValue();
}

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

private static void renameNodeReference(List<Element> elements, String attributeName, String oldNodeName, String newNodeName) {
  for (Element c : elements) {
    Attr nodeRef = c.getAttributeNode(attributeName);
    String nodeName = nodeRef.getValue();
    if (oldNodeName.equals(nodeName)) {
      nodeRef.setValue(newNodeName);
    }
  }
}

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

/**
 * Returns the value of an attribute of an element. Returns null
 * if the attribute is not found (whereas Element.getAttribute
 * returns "" if an attrib is not found). This method should be
 * used for elements that support extension attributes because it
 * does not track unexpected attributes.
 *
 * @param el       Element whose attrib is looked for
 * @param attrName name of attribute to look for
 * @return the attribute value
 */
static public String getAttribute (Element el, String attrName) {
 String sRet = null;
 Attr   attr = el.getAttributeNode(attrName);
 if (attr != null) {
  sRet = attr.getValue();
 }
 return sRet;
}

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

private static boolean isNodeWithPrototype(Element e, String nodePrototype) {
  if (e.getTagName().equals("node")) {
    Attr prototype = e.getAttributeNode("prototype");
    if (prototype != null && prototype.getValue().equals(nodePrototype)) {
      return true;
    }
  }
  return false;
}

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

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

相关文章

微信公众号

最新文章

更多