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

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

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

  1. public String getAttribute(String namespace, String name) {
  2. if (currentNode == null) {
  3. return null;
  4. }
  5. Element element = (Element) currentNode;
  6. if (element.hasAttributeNS(namespace, name)) {
  7. return element.getAttributeNS(namespace, name).trim();
  8. } else if (applicationNamespace.equals(namespace)
  9. && element.hasAttributeNS(AttributeResource.RES_AUTO_NS_URI, name)) {
  10. return element.getAttributeNS(AttributeResource.RES_AUTO_NS_URI, name).trim();
  11. }
  12. return null;
  13. }

代码示例来源:origin: com.sun.xml.bind/jaxb-impl

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

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

  1. public void handleElement(Element el) {
  2. EventTarget target = this.target.get();
  3. if (el.hasAttribute("Id")) {
  4. el.setIdAttribute("Id", true);
  5. }
  6. setListener(target, this, false);
  7. if (OO_DIGSIG_NS.equals(el.getNamespaceURI())) {
  8. String parentNS = el.getParentNode().getNamespaceURI();
  9. if (!OO_DIGSIG_NS.equals(parentNS) && !el.hasAttributeNS(XML_NS, "mdssi")) {
  10. el.setAttributeNS(XML_NS, "xmlns:mdssi", OO_DIGSIG_NS);
  11. }
  12. }
  13. setPrefix(el);
  14. setListener(target, this, true);
  15. }

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

  1. continue;
  2. if (childElement.hasAttributeNS(namespaceNs,
  3. currentAttr.getLocalName())) {
  4. continue;

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

  1. public boolean hasAttribute(String namespaceUri, String localName) {
  2. synchronized(document) {
  3. return element.hasAttributeNS(namespaceUri, localName);
  4. }
  5. }

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

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

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

  1. protected String getUnusedGenericNsPrefix() {
  2. synchronized(document) {
  3. Element documentElement = document.getDocumentElement();
  4. if (documentElement == null) {
  5. return GENERIC_NS_PREFIX + "0";
  6. }
  7. else {
  8. for (int i = 0; i < Integer.MAX_VALUE; i++) {
  9. if (!documentElement.hasAttributeNS(XMLNS_ATTRIBUTE_NS_URI, GENERIC_NS_PREFIX + i)) {
  10. return GENERIC_NS_PREFIX + i;
  11. }
  12. }
  13. throw new ModelException("Unable to find an unused namespace prefix");
  14. }
  15. }
  16. }

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

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

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

  1. private Row readRow(Element row) throws DOMException, FHIRException {
  2. Row res = new Row();
  3. int ndx = 1;
  4. NodeList cells = row.getElementsByTagNameNS(XLS_NS, "Cell");
  5. for (int i = 0; i < cells.getLength(); i++) {
  6. Element cell = (Element) cells.item(i);
  7. if (cell.hasAttributeNS(XLS_NS, "Index")) {
  8. int index = Integer.parseInt(cell.getAttributeNS(XLS_NS, "Index"));
  9. while (ndx < index) {
  10. res.add("");
  11. ndx++;
  12. }
  13. }
  14. res.add(readData(cell, ndx, res.size() > 0 ? res.get(0) : "?"));
  15. ndx++;
  16. }
  17. return res;
  18. }

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

  1. private Row readRow(Element row) throws DOMException, FHIRException {
  2. Row res = new Row();
  3. int ndx = 1;
  4. NodeList cells = row.getElementsByTagNameNS(XLS_NS, "Cell");
  5. for (int i = 0; i < cells.getLength(); i++) {
  6. Element cell = (Element) cells.item(i);
  7. if (cell.hasAttributeNS(XLS_NS, "Index")) {
  8. int index = Integer.parseInt(cell.getAttributeNS(XLS_NS, "Index"));
  9. while (ndx < index) {
  10. res.add("");
  11. ndx++;
  12. }
  13. }
  14. res.add(readData(cell, ndx, res.size() > 0 ? res.get(0) : "?"));
  15. ndx++;
  16. }
  17. return res;
  18. }

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

  1. private String extractSystemPropertiesAttribute(Element element) {
  2. for (String uri : EXT_URIS) {
  3. if (element.hasAttributeNS(uri, SYSTEM_PROPERTIES_ATTRIBUTE)) {
  4. return element.getAttributeNS(uri, SYSTEM_PROPERTIES_ATTRIBUTE);
  5. }
  6. }
  7. return null;
  8. }

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

  1. /** {@inheritDoc} */
  2. protected void doParse(Element element, ParserContext parserContext, BeanDefinitionBuilder builder) {
  3. super.doParse(element, parserContext, builder);
  4. builder.addConstructorArgReference(element.getAttributeNS(null, "resolver"));
  5. if (element.hasAttributeNS(null, "filter")) {
  6. builder.addPropertyReference("filteringEngine", element.getAttributeNS(null, "filter"));
  7. }
  8. }
  9. }

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

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

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

  1. /** {@inheritDoc} */
  2. protected void doParse(Element element, ParserContext parserContext, BeanDefinitionBuilder builder) {
  3. super.doParse(element, parserContext, builder);
  4. if(element.hasAttributeNS(null, "nameFormat")){
  5. builder.addPropertyValue("nameFormat", element.getAttributeNS(null, "nameFormat"));
  6. }else{
  7. builder.addPropertyValue("nameFormat", "urn:oasis:names:tc:SAML:1.1:nameid-format:unspecified");
  8. }
  9. builder.addPropertyValue("nameQualifier", element.getAttributeNS(null, "nameQualifier"));
  10. }
  11. }

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

  1. /** {@inheritDoc} */
  2. protected void doParse(Element element, ParserContext parserContext, BeanDefinitionBuilder builder) {
  3. super.doParse(element, parserContext, builder);
  4. builder.addPropertyValue("name", element.getAttributeNS(null, "attributeName"));
  5. if (element.hasAttributeNS(null, "attributeNameFormat")) {
  6. builder.addPropertyValue("nameFormat", element.getAttributeNS(null, "attributeNameFormat"));
  7. }
  8. }
  9. }

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

  1. /** {@inheritDoc} */
  2. protected void doParse(Element config, BeanDefinitionBuilder builder) {
  3. log.info("Parsing configuration for JSP error handler.");
  4. super.doParse(config, builder);
  5. if(config.hasAttributeNS(null, "jspPagePath")){
  6. builder.addConstructorArgValue(config.getAttributeNS(null, "jspPagePath"));
  7. }else{
  8. builder.addConstructorArgValue(config.getAttributeNS(null, "/error.jsp"));
  9. }
  10. }

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

  1. /** {@inheritDoc} */
  2. @Override protected void doParse(@Nonnull final Element config, @Nonnull final ParserContext parserContext,
  3. @Nonnull final BeanDefinitionBuilder builder) {
  4. super.doParse(config, parserContext, builder);
  5. if (config.hasAttributeNS(null, NAME_FORMAT_ATTRIBUTE_NAME)) {
  6. final String nameFormat = StringSupport.trimOrNull(config.getAttributeNS(null, NAME_FORMAT_ATTRIBUTE_NAME));
  7. builder.addPropertyValue("nameFormat", nameFormat);
  8. }
  9. builder.addPropertyValue("friendlyName", config.getAttribute(FRIENDLY_NAME_ATTRIBUTE_NAME));
  10. }

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

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

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

  1. /** {@inheritDoc} */
  2. @Override protected void doNativeParse(@Nonnull final Element element, @Nonnull final ParserContext parserContext,
  3. @Nonnull final BeanDefinitionBuilder builder) {
  4. super.doParse(element, builder);
  5. builder.addPropertyValue("matchString", StringSupport.trimOrNull(element.getAttributeNS(null, "value")));
  6. if (element.hasAttributeNS(null, "ignoreCase")) {
  7. builder.addPropertyValue("ignoreCase",
  8. StringSupport.trimOrNull(element.getAttributeNS(null, "ignoreCase")));
  9. }
  10. }
  11. }

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

  1. /** {@inheritDoc} */
  2. protected void doParse(Element element, BeanDefinitionBuilder builder) {
  3. builder.addConstructorArgReference(DatatypeHelper.safeTrimOrNullString(element.getAttributeNS(null,
  4. "trustEngineRef")));
  5. if (element.hasAttributeNS(null, "requireSignedMetadata")) {
  6. builder.addPropertyValue("requireSignature", XMLHelper.getAttributeValueAsBoolean(element
  7. .getAttributeNodeNS(null, "requireSignedMetadata")));
  8. }else{
  9. builder.addPropertyValue("requireSignature", false);
  10. }
  11. }

相关文章