Java XML Element Print printElementStart(Element elem, StringWriter sw)

Here you can find the source of printElementStart(Element elem, StringWriter sw)

Description

Print a single element node to the current buffer

License

Open Source License

Parameter

Parameter Description
elem the element in question

Declaration

static void printElementStart(Element elem, StringWriter sw) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

import java.io.StringWriter;

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

public class Main {
    /**//  w w  w  . j  av  a2 s  .  c  om
     * Print a single element node to the current buffer
     * @param elem the element in question
     */
    static void printElementStart(Element elem, StringWriter sw) {
        sw.write("<");
        sw.write(elem.getNodeName());
        NamedNodeMap attrs = elem.getAttributes();
        for (int j = 0; j < attrs.getLength(); j++) {
            Node attr = attrs.item(j);
            sw.write(" ");
            sw.write(attr.getNodeName());
            sw.write("=\"");
            sw.write(attr.getNodeValue());
            sw.write("\"");
        }
        if (elem.getFirstChild() == null)
            sw.write("/>");
        else
            sw.write(">");
    }
}

Related

  1. printElement(Element e)
  2. printElement(SOAPElement el)
  3. printElementBody(Element elem, StringWriter sw)
  4. printElementEnd(Element elem, StringWriter sw)
  5. printElemShallow(Element elem, String endient, PrintStream pstrm)
  6. printMethodArgs(Element elem, String endient, PrintStream pstrm)