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

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

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

Element.setAttributeNS介绍

[英]Adds a new attribute. If an attribute with the same local name and namespace URI is already present on the element, its prefix is changed to be the prefix part of the qualifiedName, and its value is changed to be the value parameter. This value is a simple string; it is not parsed as it is being set. So any markup (such as syntax to be recognized as an entity reference) is treated as literal text, and needs to be appropriately escaped by the implementation when it is written out. In order to assign an attribute value that contains entity references, the user must create an Attr node plus any Text and EntityReference nodes, build the appropriate subtree, and use setAttributeNodeNS or setAttributeNode to assign it as the value of an attribute.
Per [XML Namespaces] , applications must use the value null as the namespaceURI parameter for methods if they wish to have no namespace.
[中]添加新属性。如果元素上已存在具有相同本地名称和命名空间URI的属性,则其前缀将更改为qualifiedName的前缀部分,其值将更改为value参数。这个值是一个简单的字符串;它在设置时不会被解析。因此,任何标记(如要识别为实体引用的语法)都被视为文字文本,并且需要在写出时由实现进行适当的转义。为了分配包含实体引用的属性值,用户必须创建Attr节点加上任何TextEntityReference节点,构建适当的子树,并使用setAttributeNodeNSsetAttributeNode将其分配为属性值。
根据[{$0$}],如果应用程序希望没有命名空间,则必须将值null用作方法的namespaceURI参数。

代码示例

代码示例来源:origin: spring-projects/spring-framework

@Override
public void startElement(String uri, String localName, String qName, Attributes attributes) {
  Node parent = getParent();
  Element element = this.document.createElementNS(uri, qName);
  for (int i = 0; i < attributes.getLength(); i++) {
    String attrUri = attributes.getURI(i);
    String attrQname = attributes.getQName(i);
    String value = attributes.getValue(i);
    if (!attrQname.startsWith("xmlns")) {
      element.setAttributeNS(attrUri, attrQname, value);
    }
  }
  element = (Element) parent.appendChild(element);
  this.elements.add(element);
}

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

@Override
public void marshalParams(XMLStructure parent, XMLCryptoContext context) throws MarshalException {
  LOG.log(POILogger.DEBUG, "marshallParams(parent,context)");
  DOMStructure domParent = (DOMStructure) parent;
  Element parentNode = (Element)domParent.getNode();
  Document doc = parentNode.getOwnerDocument();
  
  for (String sourceId : this.sourceIds) {
    Element el = doc.createElementNS(OO_DIGSIG_NS, "mdssi:RelationshipReference");
    el.setAttributeNS(XML_NS, "xmlns:mdssi", OO_DIGSIG_NS);
    el.setAttribute("SourceId", sourceId);
    parentNode.appendChild(el);
  }
}

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

public Element encode(Object object, Document document, Element value) throws Exception {
    FunctionName function = (FunctionName) object;
    value.appendChild(document.createTextNode(function.getName()));
    value.setAttributeNS("", "nArgs", function.getArgumentCount() + "");

    return value;
  }
}

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

int iconPadding,
         ProcessDiagramSVGGraphics2D svgGenerator) {
Element gTag = svgGenerator.getDOMFactory().createElementNS(null,
                              SVGGraphics2D.SVG_G_TAG);
gTag.setAttributeNS(null,
          "transform",
          "translate(" + (imageX - 8) + "," + (imageY - 6) + ")");
Element polygonTag1 = svgGenerator.getDOMFactory().createElementNS(null,
                                  SVGGraphics2D.SVG_POLYGON_TAG);
polygonTag1.setAttributeNS(null,
              "points",
              "14 8 14 22 7 15 ");
polygonTag1.setAttributeNS(null,
              "fill",
              this.getFillValue());
polygonTag1.setAttributeNS(null,
              "stroke",
              this.getStrokeValue());
polygonTag1.setAttributeNS(null,
              "stroke-width",
              this.getStrokeWidth());
polygonTag1.setAttributeNS(null,
              "stroke-linecap",
              "butt");
polygonTag1.setAttributeNS(null,
              "stroke-linejoin",
              "miter");
polygonTag1.setAttributeNS(null,

代码示例来源:origin: org.springframework/spring-core

@Override
public void startElement(String uri, String localName, String qName, Attributes attributes) {
  Node parent = getParent();
  Element element = this.document.createElementNS(uri, qName);
  for (int i = 0; i < attributes.getLength(); i++) {
    String attrUri = attributes.getURI(i);
    String attrQname = attributes.getQName(i);
    String value = attributes.getValue(i);
    if (!attrQname.startsWith("xmlns")) {
      element.setAttributeNS(attrUri, attrQname, value);
    }
  }
  element = (Element) parent.appendChild(element);
  this.elements.add(element);
}

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

static Element functionName(Document document, Node parent, String name, int nargs) {
  Element function = element(document, parent, new QName(OGC.NAMESPACE, "FunctionName"));
  function.setAttributeNS("", "nArgs", nargs + "");
  function.appendChild(document.createTextNode(name));
  return function;
}

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

int iconPadding,
         ProcessDiagramSVGGraphics2D svgGenerator) {
Element gTag = svgGenerator.getDOMFactory().createElementNS(null,
                              SVGGraphics2D.SVG_G_TAG);
gTag.setAttributeNS(null,
          "transform",
          "translate(" + (imageX - 8) + "," + (imageY - 6) + ")");
Element polygonTag1 = svgGenerator.getDOMFactory().createElementNS(null,
                                  SVGGraphics2D.SVG_POLYGON_TAG);
polygonTag1.setAttributeNS(null,
              "points",
              "14 8 14 22 7 15 ");
polygonTag1.setAttributeNS(null,
              "fill",
              this.getFillValue());
polygonTag1.setAttributeNS(null,
              "stroke",
              this.getStrokeValue());
polygonTag1.setAttributeNS(null,
              "stroke-width",
              this.getStrokeWidth());
polygonTag1.setAttributeNS(null,
              "stroke-linecap",
              "butt");
polygonTag1.setAttributeNS(null,
              "stroke-linejoin",
              "miter");
polygonTag1.setAttributeNS(null,

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

/**
 * Method createDSctx
 *
 * @param doc
 * @param prefix
 * @param namespace
 * @return the element.
 */
public static Element createDSctx(Document doc, String prefix, String namespace) {
  if (prefix == null || prefix.trim().length() == 0) {
    throw new IllegalArgumentException("You must supply a prefix");
  }
  Element ctx = doc.createElementNS(null, "namespaceContext");
  ctx.setAttributeNS(Constants.NamespaceSpecNS, "xmlns:" + prefix.trim(), namespace);
  return ctx;
}

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

static Element functionName(Document document, Node parent, String name, int nargs) {
  Element function = element(document, parent, new QName(OGC.NAMESPACE, "Function_Name"));
  function.setAttributeNS("", "nArgs", nargs + "");
  function.appendChild(document.createTextNode(name));
  return function;
}

代码示例来源:origin: 4thline/cling

@Override
public void startElement(String uri, String localName, String qName, Attributes attributes) throws SAXException {
  super.startElement(uri, localName, qName, attributes);
  Element newEl = getInstance().getMetadata().createElementNS(uri, qName);
  for (int i = 0; i < attributes.getLength(); i++) {
    newEl.setAttributeNS(
      attributes.getURI(i),
      attributes.getQName(i),
      attributes.getValue(i)
    );
  }
  current.appendChild(newEl);
  current = newEl;
}

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

/**
 * This method creates an Element in a given namespace with a given localname.
 * It uses the {@link ElementProxy#getDefaultPrefix} method to decide whether
 * a particular prefix is bound to that namespace.
 * <BR />
 * This method was refactored out of the constructor.
 *
 * @param doc
 * @param namespace
 * @param localName
 * @return The element created.
 */
public static Element createElementForFamily(Document doc, String namespace, String localName) {
  Element result = null;
  String prefix = ElementProxy.getDefaultPrefix(namespace);
  if (namespace == null) {
    result = doc.createElementNS(null, localName);
  } else {
    if (prefix == null || prefix.length() == 0) {
      result = doc.createElementNS(namespace, localName);
      result.setAttributeNS(Constants.NamespaceSpecNS, "xmlns", namespace);
    } else {
      result = doc.createElementNS(namespace, prefix + ":" + localName);
      result.setAttributeNS(Constants.NamespaceSpecNS, "xmlns:" + prefix, namespace);
    }
  }
  return result;
}

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

for (Attribute attribute : attributes)
  esimple.setAttributeNS(attribute.getNamespace(), attribute.getName(), attribute.getValue());
parent.appendChild(esimple);
parent.appendChild(asimple);
asimple.appendChild(econtainer);

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

public void drawIcon(final int imageX,
           final int imageY,
           final int iconPadding,
           final ProcessDiagramSVGGraphics2D svgGenerator) {
  Element gTag = svgGenerator.getDOMFactory().createElementNS(null,
                                SVGGraphics2D.SVG_G_TAG);
  gTag.setAttributeNS(null,
            "transform",
            "translate(" + (imageX - 7) + "," + (imageY - 7) + ")");
  Element pathTag = svgGenerator.getDOMFactory().createElementNS(null,
                                  SVGGraphics2D.SVG_PATH_TAG);
  pathTag.setAttributeNS(null,
              "d",
              this.getDValue());
  pathTag.setAttributeNS(null,
              "style",
              this.getStyleValue());
  pathTag.setAttributeNS(null,
              "fill",
              this.getFillValue());
  pathTag.setAttributeNS(null,
              "stroke",
              this.getStrokeValue());
  gTag.appendChild(pathTag);
  svgGenerator.getExtendDOMGroupManager().addElement(gTag);
}

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

protected Element createElementForFamilyLocal(
  String namespace, String localName
) {
  Document doc = getDocument();
  Element result = null;
  if (namespace == null) {
    result = doc.createElementNS(null, localName);
  } else {
    String baseName = this.getBaseNamespace();
    String prefix = ElementProxy.getDefaultPrefix(baseName);
    if (prefix == null || prefix.length() == 0) {
      result = doc.createElementNS(namespace, localName);
      result.setAttributeNS(Constants.NamespaceSpecNS, "xmlns", namespace);
    } else {
      result = doc.createElementNS(namespace, prefix + ":" + localName);
      result.setAttributeNS(Constants.NamespaceSpecNS, "xmlns:" + prefix, namespace);
    }
  }          
  return result;
}

代码示例来源:origin: stackoverflow.com

//add the Category
Element Category = doc.createElement("category");
Rows.appendChild(Category);
if(excel.getCategory() != null){
  Category.appendChild(doc.createTextNode(excel.getCategory()));
} else {
  Category.setAttributeNS(XMLConstants.W3C_XML_SCHEMA_INSTANCE_NS_URI,
              "xsi:nil", "true");
}

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

public void drawIcon(final int imageX,
           final int imageY,
           final int iconPadding,
           final ProcessDiagramSVGGraphics2D svgGenerator) {
  Element gTag = svgGenerator.getDOMFactory().createElementNS(null,
                                SVGGraphics2D.SVG_G_TAG);
  gTag.setAttributeNS(null,
            "transform",
            "translate(" + (imageX - 1) + "," + (imageY - 2) + ")");
  Element pathTag = svgGenerator.getDOMFactory().createElementNS(null,
                                  SVGGraphics2D.SVG_PATH_TAG);
  pathTag.setAttributeNS(null,
              "d",
              this.getDValue());
  pathTag.setAttributeNS(null,
              "fill",
              this.getFillValue());
  pathTag.setAttributeNS(null,
              "stroke",
              this.getStrokeValue());
  pathTag.setAttributeNS(null,
              "stroke-widthh",
              this.getStrokeWidth());
  gTag.appendChild(pathTag);
  svgGenerator.getExtendDOMGroupManager().addElement(gTag);
}

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

public void startElement(String namespace, String localName, String qName,
Attributes attrs) 
final Element tmp = (Element)_document.createElementNS(namespace, qName);
    tmp.setAttributeNS(XMLNS_URI, XMLNS_PREFIX,
    (String) _namespaceDecls.elementAt(i));
    tmp.setAttributeNS(XMLNS_URI, XMLNS_STRING + prefix, 
    (String) _namespaceDecls.elementAt(i));
  tmp.setAttributeNS(attrs.getURI(i), attrs.getQName(i), 
    attrs.getValue(i));

代码示例来源:origin: stackoverflow.com

Element defs = doc.createElementNS(svgNS, "defs");

Element fontface = doc.createElementNS(svgNS, "font-face");
fontface.setAttributeNS(null, "font-family", "DroidSansRegular");

Element fontfacesrc = doc.createElementNS(svgNS, "font-face-src");
Element fontfaceuri = doc.createElementNS(svgNS, "font-face-uri");

fontfaceuri.setAttributeNS(svgNS, "xlink:href", "fonts/DroidSans-webfont.svg#DroidSansRegular");

Element fontfaceformat = doc.createElementNS(svgNS, "font-face-format");
fontfaceformat.setAttributeNS(svgNS, "string", "svg");

fontfaceuri.appendChild(fontfaceformat);
fontfacesrc.appendChild(fontfaceuri);
fontface.appendChild(fontfacesrc);
defs.appendChild(fontface);
svgRoot.appendChild(defs);

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

public void drawIcon(final int imageX,
           final int imageYo,
           final int iconPadding,
           final ProcessDiagramSVGGraphics2D svgGenerator) {
  Element gTag = svgGenerator.getDOMFactory().createElementNS(null,
                                SVGGraphics2D.SVG_G_TAG);
  gTag.setAttributeNS(null,
            "transform",
            "translate(" + (imageX) + "," + (imageYo) + ")");
  Element pathTag = svgGenerator.getDOMFactory().createElementNS(null,
                                  SVGGraphics2D.SVG_PATH_TAG);
  pathTag.setAttributeNS(null,
              "d",
              this.getDValue());
  pathTag.setAttributeNS(null,
              "fill",
              this.getFillValue());
  pathTag.setAttributeNS(null,
              "stroke",
              this.getStrokeValue());
  gTag.appendChild(pathTag);
  svgGenerator.getExtendDOMGroupManager().addElement(gTag);
}

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

static class LoggingErrorListener implements ErrorListener {
    // See http://www.cafeconleche.org/slides/sd2003west/xmlandjava/346.html
  
  boolean strict;
    public LoggingErrorListener(boolean strict) {
  }
  
  public void warning(TransformerException exception) {
      log.warn(exception.getMessage(), exception);
      // Don't throw an exception and stop the processor
   // just for a warning; but do log the problem
  }
  
  public void error(TransformerException exception)
   throws TransformerException {
   
    log.error(exception.getMessage(), exception);
   
    // XSLT is not as draconian as XML. There are numerous errors
   // which the processor may but does not have to recover from; 
   // e.g. multiple templates that match a node with the same
   // priority. If I do not want to allow that,  I'd throw this 
   // exception here.
    if (strict) {
      throw exception;
    }

相关文章

微信公众号

最新文章

更多