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

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

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

Element.hasAttributeNS介绍

[英]Returns true when an attribute with a given local name and namespace URI is specified on this element or has a default value, false otherwise.
Per [XML Namespaces] , applications must use the value null as the namespaceURI parameter for methods if they wish to have no namespace.
[中]当在此元素上指定了具有给定本地名称和命名空间URI的属性或具有默认值时,返回true,否则返回false
根据[{$0$}],如果应用程序希望没有命名空间,则必须将值null用作方法的namespaceURI参数。

代码示例

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

public String getAttribute(String namespace, String name) {
 if (currentNode == null) {
  return null;
 }
 Element element = (Element) currentNode;
 if (element.hasAttributeNS(namespace, name)) {
  return element.getAttributeNS(namespace, name).trim();
 } else if (applicationNamespace.equals(namespace)
   && element.hasAttributeNS(AttributeResource.RES_AUTO_NS_URI, name)) {
  return element.getAttributeNS(AttributeResource.RES_AUTO_NS_URI, name).trim();
 }
 return null;
}

代码示例来源: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: org.apache.poi/poi-ooxml

public void handleElement(Element el) {
  EventTarget target = this.target.get();
  if (el.hasAttribute("Id")) {
    el.setIdAttribute("Id", true);
  }
  setListener(target, this, false);
  if (OO_DIGSIG_NS.equals(el.getNamespaceURI())) {
    String parentNS = el.getParentNode().getNamespaceURI();
    if (!OO_DIGSIG_NS.equals(parentNS) && !el.hasAttributeNS(XML_NS, "mdssi")) {
      el.setAttributeNS(XML_NS, "xmlns:mdssi", OO_DIGSIG_NS);
    }
  }
  setPrefix(el);
  setListener(target, this, true);
}

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

continue;
if (childElement.hasAttributeNS(namespaceNs, 
                currentAttr.getLocalName())) {
  continue;

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

public boolean hasAttribute(String namespaceUri, String localName) {
 synchronized(document) {
  return element.hasAttributeNS(namespaceUri, localName);
 }
}

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

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

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

protected String getUnusedGenericNsPrefix() {
 synchronized(document) {
  Element documentElement = document.getDocumentElement();
  if (documentElement == null) {
   return GENERIC_NS_PREFIX + "0";
  }
  else {
   for (int i = 0; i < Integer.MAX_VALUE; i++) {
    if (!documentElement.hasAttributeNS(XMLNS_ATTRIBUTE_NS_URI, GENERIC_NS_PREFIX + i)) {
     return GENERIC_NS_PREFIX + i;
    }
   }
   throw new ModelException("Unable to find an unused namespace prefix");
  }
 }
}

代码示例来源: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: jamesagnew/hapi-fhir

private Row readRow(Element row) throws DOMException, FHIRException  {
 Row res = new Row();
 int ndx = 1;    
 NodeList cells = row.getElementsByTagNameNS(XLS_NS, "Cell");
 for (int i = 0; i < cells.getLength(); i++) {
  Element cell = (Element) cells.item(i);
  if (cell.hasAttributeNS(XLS_NS, "Index")) {
   int index = Integer.parseInt(cell.getAttributeNS(XLS_NS, "Index"));
   while (ndx < index) {
    res.add("");
    ndx++;
   }
  }
  res.add(readData(cell, ndx, res.size() > 0 ? res.get(0) : "?"));
  ndx++;      
 }
 return res;
}

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

private Row readRow(Element row) throws DOMException, FHIRException  {
 Row res = new Row();
 int ndx = 1;    
 NodeList cells = row.getElementsByTagNameNS(XLS_NS, "Cell");
 for (int i = 0; i < cells.getLength(); i++) {
  Element cell = (Element) cells.item(i);
  if (cell.hasAttributeNS(XLS_NS, "Index")) {
   int index = Integer.parseInt(cell.getAttributeNS(XLS_NS, "Index"));
   while (ndx < index) {
    res.add("");
    ndx++;
   }
  }
  res.add(readData(cell, ndx, res.size() > 0 ? res.get(0) : "?"));
  ndx++;      
 }
 return res;
}

代码示例来源:origin: org.apache.aries.blueprint/org.apache.aries.blueprint.cm

private String extractSystemPropertiesAttribute(Element element) {
  for (String uri : EXT_URIS) {
    if (element.hasAttributeNS(uri, SYSTEM_PROPERTIES_ATTRIBUTE)) {
      return element.getAttributeNS(uri, SYSTEM_PROPERTIES_ATTRIBUTE);
    }
  }
  return null;
}

代码示例来源:origin: edu.internet2.middleware/shibboleth-common

/** {@inheritDoc} */
  protected void doParse(Element element, ParserContext parserContext, BeanDefinitionBuilder builder) {
    super.doParse(element, parserContext, builder);

    builder.addConstructorArgReference(element.getAttributeNS(null, "resolver"));

    if (element.hasAttributeNS(null, "filter")) {
      builder.addPropertyReference("filteringEngine", element.getAttributeNS(null, "filter"));
    }
  }
}

代码示例来源:origin: edu.internet2.middleware/shibboleth-common

/** {@inheritDoc} */
protected String resolveId(Element configElement, AbstractBeanDefinition beanDefinition, ParserContext parserContext) {
  if(!configElement.hasAttributeNS(null, "id")){
    log.warn("AttributeFilterPolicy elements should include an 'id' attribute.  This is not currently required but will be in future versions.");
  }
  return getQualifiedId(configElement, configElement.getLocalName(), configElement.getAttributeNS(null, "id"));
}

代码示例来源:origin: edu.internet2.middleware/shibboleth-common

/** {@inheritDoc} */
  protected void doParse(Element element, ParserContext parserContext, BeanDefinitionBuilder builder) {
    super.doParse(element, parserContext, builder);

    if(element.hasAttributeNS(null, "nameFormat")){
      builder.addPropertyValue("nameFormat", element.getAttributeNS(null, "nameFormat"));
    }else{
      builder.addPropertyValue("nameFormat", "urn:oasis:names:tc:SAML:1.1:nameid-format:unspecified");
    }
    
    builder.addPropertyValue("nameQualifier", element.getAttributeNS(null, "nameQualifier"));
  }
}

代码示例来源:origin: edu.internet2.middleware/shibboleth-common

/** {@inheritDoc} */
  protected void doParse(Element element, ParserContext parserContext, BeanDefinitionBuilder builder) {
    super.doParse(element, parserContext, builder);

    builder.addPropertyValue("name", element.getAttributeNS(null, "attributeName"));

    if (element.hasAttributeNS(null, "attributeNameFormat")) {
      builder.addPropertyValue("nameFormat", element.getAttributeNS(null, "attributeNameFormat"));
    }
  }
}

代码示例来源:origin: edu.internet2.middleware/shibboleth-common

/** {@inheritDoc} */
protected void doParse(Element config, BeanDefinitionBuilder builder) {
  log.info("Parsing configuration for JSP error handler.");
  super.doParse(config, builder);
  if(config.hasAttributeNS(null, "jspPagePath")){
    builder.addConstructorArgValue(config.getAttributeNS(null, "jspPagePath"));
  }else{
    builder.addConstructorArgValue(config.getAttributeNS(null, "/error.jsp"));
  }
}

代码示例来源:origin: net.shibboleth.idp/idp-attribute-resolver-spring

/** {@inheritDoc} */
@Override protected void doParse(@Nonnull final Element config, @Nonnull final ParserContext parserContext,
    @Nonnull final BeanDefinitionBuilder builder) {
  super.doParse(config, parserContext, builder);
  if (config.hasAttributeNS(null, NAME_FORMAT_ATTRIBUTE_NAME)) {
    final String nameFormat = StringSupport.trimOrNull(config.getAttributeNS(null, NAME_FORMAT_ATTRIBUTE_NAME));
    builder.addPropertyValue("nameFormat", nameFormat);
  }
  builder.addPropertyValue("friendlyName", config.getAttribute(FRIENDLY_NAME_ATTRIBUTE_NAME));
}

代码示例来源:origin: net.shibboleth.idp/idp-attribute-resolver-spring

/** {@inheritDoc} */
@Override protected void doParse(@Nonnull final Element config, @Nonnull final ParserContext parserContext,
    @Nonnull final BeanDefinitionBuilder builder) {
  super.doParse(config, parserContext, builder);
  if (config.hasAttributeNS(null, NAMESPACE_ATTRIBUTE_NAME)) {
    final String namespace = StringSupport.trimOrNull(config.getAttributeNS(null, NAMESPACE_ATTRIBUTE_NAME));
    builder.addPropertyValue("namespace", namespace);
  }
}

代码示例来源:origin: net.shibboleth.idp/idp-attribute-filter-spring

/** {@inheritDoc} */
  @Override protected void doNativeParse(@Nonnull final Element element, @Nonnull final ParserContext parserContext,
      @Nonnull final BeanDefinitionBuilder builder) {
    super.doParse(element, builder);

    builder.addPropertyValue("matchString", StringSupport.trimOrNull(element.getAttributeNS(null, "value")));

    if (element.hasAttributeNS(null, "ignoreCase")) {
      builder.addPropertyValue("ignoreCase", 
          StringSupport.trimOrNull(element.getAttributeNS(null, "ignoreCase")));
    }
  }
}

代码示例来源:origin: edu.internet2.middleware/shibboleth-common

/** {@inheritDoc} */
protected void doParse(Element element, BeanDefinitionBuilder builder) {
  builder.addConstructorArgReference(DatatypeHelper.safeTrimOrNullString(element.getAttributeNS(null,
      "trustEngineRef")));
  if (element.hasAttributeNS(null, "requireSignedMetadata")) {
    builder.addPropertyValue("requireSignature", XMLHelper.getAttributeValueAsBoolean(element
        .getAttributeNodeNS(null, "requireSignedMetadata")));
  }else{
    builder.addPropertyValue("requireSignature", false);
  }
}

相关文章

微信公众号

最新文章

更多