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

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

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

Element.removeAttribute介绍

[英]Removes an attribute by name. If a default value for the removed attribute is defined in the DTD, a new attribute immediately appears with the default value as well as the corresponding namespace URI, local name, and prefix when applicable. The implementation may handle default values from other schemas similarly but applications should use Document.normalizeDocument() to guarantee this information is up-to-date.
If no attribute with this name is found, this method has no effect.
To remove an attribute by local name and namespace URI, use the removeAttributeNS method.
[中]按名称删除属性。如果在DTD中定义了已删除属性的默认值,则会立即出现一个新属性,其中包含默认值以及相应的命名空间URI、本地名称和前缀(如果适用)。该实现可以类似地处理来自其他模式的默认值,但应用程序应使用Document.normalizeDocument()来确保此信息是最新的。
如果未找到具有此名称的属性,则此方法无效。
要按本地名称和命名空间URI删除属性,请使用removeAttributeNS方法。

代码示例

代码示例来源:origin: org.netbeans.api/org-openide-util

private static void removeXmlBase(Element e) {
  e.removeAttributeNS("http://www.w3.org/XML/1998/namespace", "base"); // NOI18N
  e.removeAttribute("xml:base"); // NOI18N
}

代码示例来源:origin: org.netbeans.api/org-openide-util

private static void fixupAttrsSingle(Element e) throws DOMException {
  removeXmlBase(e);
  Map<String, String> replace = new HashMap<String, String>();
  NamedNodeMap attrs = e.getAttributes();
  for (int j = 0; j < attrs.getLength(); j++) {
    Attr attr = (Attr) attrs.item(j);
    if (attr.getNamespaceURI() == null && !attr.getName().equals("xmlns")) { // NOI18N
      replace.put(attr.getName(), attr.getValue());
    }
  }
  for (Map.Entry<String, String> entry : replace.entrySet()) {
    e.removeAttribute(entry.getKey());
    e.setAttributeNS(null, entry.getKey(), entry.getValue());
  }
}
private static void removeXmlBase(Element e) {

代码示例来源:origin: aragozin/jvm-tools

private void transformBody(Element node) throws IOException {
  for(Element e: elementsOf(node)) {
    String id = id(e);
    if (id != null && id.startsWith("debug_")) {
      if (!retainDebug) {
        node.removeChild(e);
      }
    }
    else if (id != null && id.startsWith("importflame_")) {
      String flameName = id.substring("importflame_".length());
      e.removeAttribute("id");
      e.removeAttribute("src");
      importDataSet(flameName, e);
    }
    else {
      transformBody(e);
    }            
  }                
}

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

@Signature
public void __unset(String name) {
  getWrappedObject().removeAttribute(name);
}

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

root.removeAttribute(rootAttribute);

代码示例来源:origin: aragozin/jvm-tools

e.removeAttribute("src");
      importJs(href, e);                            
e.removeAttribute("id");
e.removeAttribute("src");
importDataSet(flameName, e);

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

private void mtuPostlex(Document doc) throws DOMException {
  TreeWalker tw = ((DocumentTraversal) doc).createTreeWalker(doc, NodeFilter.SHOW_ELEMENT, new NameNodeFilter(MaryXML.MTU),
      false);
  Element m = null;
  while ((m = (Element) tw.nextNode()) != null) {
    if (MaryDomUtils.hasAncestor(m, MaryXML.MTU)) // not highest-level
      continue;
    // Now m is a highest-level mtu element
    // Search for the token whose accent is retained;
    // all other accents will be deleted.
    Element c = m;
    while (c != null && !c.getTagName().equals(MaryXML.TOKEN)) {
      String whatToAccent = c.getAttribute("accent");
      if (whatToAccent != null && whatToAccent.equals("first"))
        c = MaryDomUtils.getFirstChildElement(c);
      else
        c = MaryDomUtils.getLastChildElement(c);
    }
    Element retainAccentToken = c;
    // Now all token below m except retainAccentToken get
    // their accent deleted.
    NodeList tokens = m.getElementsByTagName(MaryXML.TOKEN);
    for (int i = 0; i < tokens.getLength(); i++) {
      Element t = (Element) tokens.item(i);
      if (t != retainAccentToken) // not the same *Object*!
        t.removeAttribute("accent");
    }
  } // for all highest-level mtu elements
}

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

private void mtuPostlex(Document doc) throws DOMException {
  TreeWalker tw = ((DocumentTraversal) doc).createTreeWalker(doc, NodeFilter.SHOW_ELEMENT, new NameNodeFilter(MaryXML.MTU),
      false);
  Element m = null;
  while ((m = (Element) tw.nextNode()) != null) {
    if (MaryDomUtils.hasAncestor(m, MaryXML.MTU)) // not highest-level
      continue;
    // Now m is a highest-level mtu element
    // Search for the token whose accent is retained;
    // all other accents will be deleted.
    Element c = m;
    while (c != null && !c.getTagName().equals(MaryXML.TOKEN)) {
      String whatToAccent = c.getAttribute("accent");
      if (whatToAccent != null && whatToAccent.equals("first"))
        c = MaryDomUtils.getFirstChildElement(c);
      else
        c = MaryDomUtils.getLastChildElement(c);
    }
    Element retainAccentToken = c;
    // Now all token below m except retainAccentToken get
    // their accent deleted.
    NodeList tokens = m.getElementsByTagName(MaryXML.TOKEN);
    for (int i = 0; i < tokens.getLength(); i++) {
      Element t = (Element) tokens.item(i);
      if (t != retainAccentToken) // not the same *Object*!
        t.removeAttribute("accent");
    }
  } // for all highest-level mtu elements
}

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

token.removeAttribute("accent"); // doesn't receive an accent
} else { // default behaviour: determine by rule whether to assign an accent
  getAccentPosition(token, tokens, i, sentenceType, specialPositionType);
  token.removeAttribute("accent");
token.removeAttribute("accent"); // if there is no accent, the accent attribute can be removed

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

token.removeAttribute("accent"); // doesn't receive an accent
} else { // default behaviour: determine by rule whether to assign an accent
  getAccentPosition(token, tokens, i, sentenceType, specialPositionType);
  token.removeAttribute("accent");
token.removeAttribute("accent"); // if there is no accent, the accent attribute can be removed

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

@Test
public void testGobalContactDefault() throws Exception {
  GeoServerInfo g1 = factory.createGlobal();
  ContactInfo contact = factory.createContact();
  g1.setContact(contact);
  ByteArrayOutputStream out = out();
  persister.save(g1, out);
  ByteArrayInputStream in = in(out);
  Document dom = dom(in);
  Element e = (Element) dom.getElementsByTagName("contact").item(0);
  e.removeAttribute("class");
  in = in(dom);
  GeoServerInfo g2 = persister.load(in, GeoServerInfo.class);
  assertEquals(g1, g2);
}

代码示例来源:origin: org.apache.commons/commons-configuration2

/**
 * Removes all attributes of the given element.
 *
 * @param elem the element
 */
private static void clearAttributes(final Element elem)
{
  final NamedNodeMap attributes = elem.getAttributes();
  for (int i = 0; i < attributes.getLength(); i++)
  {
    elem.removeAttribute(attributes.item(i).getNodeName());
  }
}

代码示例来源:origin: takari/polyglot-maven

for (int i = 0; i < attrs.getLength(); i++) {
 Attr attr = (Attr) attrs.item(i);
 root.removeAttribute(attr.getName());
root.removeAttribute("xmlns:xsi");

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

dom.getDocumentElement().removeAttribute("resultType");

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

protected void processNameAttribute(Element element,
                  ParserContext ctx,
                  BeanDefinitionBuilder bean,
                  String val) {
    bean.addPropertyValue("name", val);
    element.removeAttribute("name");
    if (!element.hasAttribute("id")) {
      val = "cxf.workqueue." + val;
      element.setAttribute("id", val);
    }
  }
});

代码示例来源:origin: espertechinc/esper

private static void renameAttribute(Element element, String oldName, String newName) {
  String value = element.getAttribute(oldName);
  if (value == null || value.isEmpty()) {
    return;
  }
  element.removeAttribute(oldName);
  element.setAttribute(newName, value);
}

代码示例来源:origin: espertechinc/esper

private static void removeAttributes(Element element, String namesCSV) {
  Set<String> names = toSet(namesCSV);
  for (String name : names) {
    String value = element.getAttribute(name);
    if (value != null) {
      element.removeAttribute(name);
    }
  }
}

代码示例来源:origin: elki-project/elki

@Override
 public void handleEvent(Event evt) {
  if(checked ^= true) {
   checkmark.removeAttribute(SVGConstants.SVG_STYLE_ATTRIBUTE);
  }
  else {
   checkmark.setAttribute(SVGConstants.SVG_STYLE_ATTRIBUTE, SVGConstants.CSS_DISPLAY_PROPERTY + ":" + SVGConstants.CSS_NONE_VALUE);
  }
  fireSwitchEvent(new ChangeEvent(SVGCheckbox.this));
 }
}, false);

代码示例来源:origin: org.mule.modules/mule-module-spring-config

@Override
  protected void preProcess(Element element)
  {
    //This causes the Bean framework to process the "ref" as a string rather than a ref to another object
    if(StringUtils.isNotEmpty(element.getAttribute("ref")))
    {
      element.setAttribute("reference", element.getAttribute("ref"));
      element.removeAttribute("ref");
    }
    super.preProcess(element);

  }
}

代码示例来源:origin: org.mule.modules/mule-module-spring-config

private void handleParentAttribute(Element element, BeanDefinitionBuilder builder)
{
  final String parentAttribute = element.getAttribute(PARENT_ATTRIBUTE);
  if (StringUtils.isNotBlank(parentAttribute))
  {
    builder.setParentName(parentAttribute);
  }
  element.removeAttribute(PARENT_ATTRIBUTE);
}

相关文章

微信公众号

最新文章

更多