Java XML Node to String nodeToString(Node node)

Here you can find the source of nodeToString(Node node)

Description

node To String

License

Open Source License

Declaration

public static String nodeToString(Node node) 

Method Source Code

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

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

public class Main {
    public static String nodeToString(Node node) {
        String ret = "<null/>";
        if (node != null) {
            ret = "<" + node.getNodeName() + " ";
            NamedNodeMap attrs = node.getAttributes();
            if (attrs != null) {
                for (int i = 0; i < attrs.getLength(); i++) {
                    Node attr = (Node) attrs.item(i);
                    ret = ret + attr.getNodeName() + "='";
                    ret = ret + attr.getNodeValue() + "' ";
                }//from w w  w .  j a v a 2 s.c om
            }
            ret = ret + "/>";
        }
        return ret;
    }
}

Related

  1. nodeToString(Node doc)
  2. nodeToString(Node n)
  3. nodeToString(Node n)
  4. nodeToString(Node n)
  5. nodeToString(Node node)
  6. nodeToString(Node node)
  7. nodeToString(Node node)
  8. nodeToString(Node node)
  9. nodeToString(Node node)