Java XML Attribute Append appendAttributes(Node node, StringBuffer sb)

Here you can find the source of appendAttributes(Node node, StringBuffer sb)

Description

append Attributes

License

LGPL

Declaration

private static void appendAttributes(Node node, StringBuffer sb) 

Method Source Code

//package com.java2s;
/*/*  w  w w  .ja  va2  s . c o m*/
 * www.openamf.org
 *
 * Distributable under LGPL license.
 * See terms of license at gnu.org.
 */

import org.w3c.dom.Element;
import org.w3c.dom.NamedNodeMap;
import org.w3c.dom.Node;

public class Main {
    private static void appendAttributes(Node node, StringBuffer sb) {
        if (node instanceof Element) {
            NamedNodeMap nodeMap = node.getAttributes();
            for (int i = 0; i < nodeMap.getLength(); i++) {
                sb.append(' ');
                sb.append(nodeMap.item(i).getNodeName());
                sb.append('=');
                sb.append('"');
                sb.append(nodeMap.item(i).getNodeValue());
                sb.append('"');
            }
        }
    }
}

Related

  1. appendAllAttributes(Node node, StringBuffer xpath)
  2. appendAttribute(Node node, String name, String value)
  3. appendAttributeIfNotNull(Element parentElement, String attributeName, Object attributeValue)
  4. appendAttributeNode(String namespace, Element parent, String name, String value)
  5. appendBooleanAttribute(Element thisElement, String attrName, boolean value)
  6. appendBooleanElement(Element parentElement, String nodeName, boolean value)