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

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

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

Element.removeAttributeNS介绍

[英]Removes an attribute by local name and namespace URI. 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 local name and namespace URI is found, this method has no effect.
Per [XML Namespaces] , applications must use the value null as the namespaceURI parameter for methods if they wish to have no namespace.
[中]按本地名称和命名空间URI删除属性。如果在DTD中定义了已删除属性的默认值,则会立即出现一个新属性,其中包含默认值以及相应的命名空间URI、本地名称和前缀(如果适用)。该实现可以类似地处理来自其他模式的默认值,但应用程序应使用Document.normalizeDocument()来确保此信息是最新的。
如果未找到具有此本地名称和命名空间URI的属性,则此方法无效。
根据[{$0$}],如果应用程序希望没有命名空间,则必须将值null用作方法的namespaceURI参数。

代码示例

代码示例来源: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: com.sun.xml.bind/jaxb-impl

protected void namespace(Element element, String prefix, String uri) {
  String qname;
  if ("".equals(prefix) || prefix == null) {
    qname = "xmlns";
  } else {
    qname = "xmlns:" + prefix;
  }
  // older version of Xerces (I confirmed that the bug is gone with Xerces 2.4.0)
  // have a problem of re-setting the same namespace attribute twice.
  // work around this bug removing it first.
  if (element.hasAttributeNS("http://www.w3.org/2000/xmlns/", qname)) {
    // further workaround for an old Crimson bug where the removeAttribtueNS
    // method throws NPE when the element doesn't have any attribute.
    // to be on the safe side, check the existence of attributes before
    // attempting to remove it.
    // for details about this bug, see org.apache.crimson.tree.ElementNode2
    // line 540 or the following message:
    // https://jaxb.dev.java.net/servlets/ReadMsg?list=users&msgNo=2767
    element.removeAttributeNS("http://www.w3.org/2000/xmlns/", qname);
  }
  // workaround until here
  element.setAttributeNS("http://www.w3.org/2000/xmlns/", qname, uri);
}

代码示例来源:origin: plutext/docx4j

protected void setLocalIdAttribute(String attrName, String value) {
  
  if (value != null) {
    Attr attr = getDocument().createAttributeNS(null, attrName);
    attr.setValue(value);
    getElement().setAttributeNodeNS(attr);
    getElement().setIdAttributeNode(attr, true);
  }
  else {
    getElement().removeAttributeNS(null, attrName);
  }
}

代码示例来源:origin: jamesagnew/hapi-fhir

public static void deleteAttr(Element e, String namespaceURI, String localName) {
 if (e.hasAttributeNS(namespaceURI, localName))
  e.removeAttributeNS(namespaceURI, localName);
 
}

代码示例来源:origin: org.glassfish.jaxb/jaxb-runtime

protected void namespace(Element element, String prefix, String uri) {
  String qname;
  if ("".equals(prefix) || prefix == null) {
    qname = "xmlns";
  } else {
    qname = "xmlns:" + prefix;
  }
  // older version of Xerces (I confirmed that the bug is gone with Xerces 2.4.0)
  // have a problem of re-setting the same namespace attribute twice.
  // work around this bug removing it first.
  if (element.hasAttributeNS("http://www.w3.org/2000/xmlns/", qname)) {
    // further workaround for an old Crimson bug where the removeAttribtueNS
    // method throws NPE when the element doesn't have any attribute.
    // to be on the safe side, check the existence of attributes before
    // attempting to remove it.
    // for details about this bug, see org.apache.crimson.tree.ElementNode2
    // line 540 or the following message:
    // https://jaxb.dev.java.net/servlets/ReadMsg?list=users&msgNo=2767
    element.removeAttributeNS("http://www.w3.org/2000/xmlns/", qname);
  }
  // workaround until here
  element.setAttributeNS("http://www.w3.org/2000/xmlns/", qname, uri);
}

代码示例来源:origin: camunda/camunda-bpm-platform

public void removeAttribute(String namespaceUri, String localName) {
 synchronized(document) {
  XmlQName xmlQName = new XmlQName(this, namespaceUri, localName);
  if (xmlQName.hasLocalNamespace()) {
   element.removeAttributeNS(null, xmlQName.getLocalName());
  }
  else {
   element.removeAttributeNS(xmlQName.getNamespaceUri(), xmlQName.getLocalName());
  }
 }
}

代码示例来源:origin: ryantenney/metrics-spring

@Override
public BeanDefinition parse(Element element, ParserContext parserContext) {
  final CompositeComponentDefinition compDefinition = new CompositeComponentDefinition(element.getTagName(), parserContext.extractSource(element));
  parserContext.pushContainingComponent(compDefinition);
  final String metricRegistryBeanName = element.getAttribute("metric-registry");
  if (!StringUtils.hasText(metricRegistryBeanName)) {
    throw new RuntimeException(); // TODO
  }
  final RuntimeBeanReference metricRegistryBeanRef = new RuntimeBeanReference(metricRegistryBeanName);
  final List<Element> metricElements = DomUtils.getChildElementsByTagName(element, new String[] { "bean", "ref" });
  for (Element metricElement : metricElements) {
    // Get the name attribute and remove it (to prevent Spring from looking for a BeanDefinitionDecorator)
    final String name = metricElement.getAttributeNS(METRICS_NAMESPACE, "name");
    if (name != null) {
      metricElement.removeAttributeNS(METRICS_NAMESPACE, "name");
    }
    final Object metric = parserContext.getDelegate().parsePropertySubElement(metricElement, null);
    final RootBeanDefinition metricRegistererDef = new RootBeanDefinition(MetricRegisterer.class);
    metricRegistererDef.setSource(parserContext.extractSource(metricElement));
    metricRegistererDef.setRole(BeanDefinition.ROLE_INFRASTRUCTURE);
    final ConstructorArgumentValues args = metricRegistererDef.getConstructorArgumentValues();
    args.addIndexedArgumentValue(0, metricRegistryBeanRef);
    args.addIndexedArgumentValue(1, name);
    args.addIndexedArgumentValue(2, metric);
    final String beanName = parserContext.getReaderContext().registerWithGeneratedName(metricRegistererDef);
    parserContext.registerComponent(new BeanComponentDefinition(metricRegistererDef, beanName));
  }
  parserContext.popAndRegisterContainingComponent();
  return null;
}

代码示例来源:origin: org.virtuslab/milyn-smooks-core

public void visitAfter(Element element, ExecutionContext executionContext) throws SmooksException {
    if(namespace != null) {
      element.removeAttributeNS(namespace, localPart);
    } else {
      element.removeAttribute(localPart);
    }
  }
}

代码示例来源:origin: org.milyn/milyn-smooks-core

public void visitAfter(Element element, ExecutionContext executionContext) throws SmooksException {
    if(namespace != null) {
      element.removeAttributeNS(namespace, localPart);
    } else {
      element.removeAttribute(localPart);
    }
  }
}

代码示例来源:origin: org.milyn/milyn-smooks-all

public void visitAfter(Element element, ExecutionContext executionContext) throws SmooksException {
    if(namespace != null) {
      element.removeAttributeNS(namespace, localPart);
    } else {
      element.removeAttribute(localPart);
    }
  }
}

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

public void visitAfter(Element element, ExecutionContext executionContext) throws SmooksException {
    if(namespace != null) {
      element.removeAttributeNS(namespace, localPart);
    } else {
      element.removeAttribute(localPart);
    }
  }
}

代码示例来源:origin: net.sf.practicalxml/practicalxml

/**
 *  Sets the <code>xsi:nil</code> attribute to the passed value.
 */
public static void setXsiNil(Element elem, boolean isNil)
{
  if (isNil)
    elem.setAttributeNS(XMLConstants.W3C_XML_SCHEMA_INSTANCE_NS_URI, "nil", "true");
  else
    elem.removeAttributeNS(XMLConstants.W3C_XML_SCHEMA_INSTANCE_NS_URI, "nil");
}

代码示例来源:origin: skynav/ttt

public static void removeAttribute(Element e, QName qn) {
  String ns       = qn.getNamespaceURI();
  String ln       = qn.getLocalPart();
  if ((ns == null) || (ns.length() == 0))
    e.removeAttribute(ln);
  else
    e.removeAttributeNS(ns, ln);
}

代码示例来源:origin: org.vx68k.quercus/quercus

public void removeAttributeNS(String namespaceURI, String localName)
 throws DOMException
{
 try {
  _delegate.removeAttributeNS(namespaceURI, localName);
 }
 catch (org.w3c.dom.DOMException ex) {
  throw wrap(ex);
 }
}

代码示例来源:origin: Geomatys/geotoolkit

@Override
public void removeAttributeNS(String namespaceURI, String localName) throws DOMException {
  final Element elem = getElement();
  if (elem != null) elem.removeAttributeNS(namespaceURI, localName);
}

代码示例来源:origin: org.opensingular/form-core

/**
 * @see org.w3c.dom.Element#removeAttributeNS(String, String)
 */
@Override
public void removeAttributeNS(String arg0, String arg1) {
  original.get().removeAttributeNS(arg0, arg1);
}

代码示例来源:origin: com.js-lib/js-dom

@Override
public Element removeAttrNS(String namespaceURI, String name) {
  if (namespaceURI == null) {
    return removeAttr(name);
  }
  Params.notNullOrEmpty(name, "Attribute name");
  node.removeAttributeNS(namespaceURI, name);
  return this;
}

代码示例来源:origin: org.camunda.bpm.model/camunda-xml-model

public void removeAttribute(String namespaceUri, String localName) {
 synchronized(document) {
  XmlQName xmlQName = new XmlQName(this, namespaceUri, localName);
  if (xmlQName.hasLocalNamespace()) {
   element.removeAttributeNS(null, xmlQName.getLocalName());
  }
  else {
   element.removeAttributeNS(xmlQName.getNamespaceUri(), xmlQName.getLocalName());
  }
 }
}

代码示例来源:origin: org.apache.santuario/xmlsec

protected void setLocalIdAttribute(String attrName, String value) {
  if (value != null) {
    Attr attr = getDocument().createAttributeNS(null, attrName);
    attr.setValue(value);
    getElement().setAttributeNodeNS(attr);
    getElement().setIdAttributeNode(attr, true);
  }
  else {
    getElement().removeAttributeNS(null, attrName);
  }
}

代码示例来源:origin: org.docx4j/docx4j

protected void setLocalIdAttribute(String attrName, String value) {
  
  if (value != null) {
    Attr attr = getDocument().createAttributeNS(null, attrName);
    attr.setValue(value);
    getElement().setAttributeNodeNS(attr);
    getElement().setIdAttributeNode(attr, true);
  }
  else {
    getElement().removeAttributeNS(null, attrName);
  }
}

相关文章

微信公众号

最新文章

更多