Mega Code Archive
Convert node element To String
/**
* JBoss, Home of Professional Open Source
*
* Distributable under LGPL license.
* See terms of license at gnu.org.
*/
import org.w3c.dom.NamedNodeMap;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
/**
* @author Ovidiu Feodorov
* @version $Revision: 3282 $ $Id: XMLUtil.java 3282 2007-11-01
* 15:32:29Z timfox $
*/
public class Utils {
public static String elementToString(Node n) {
String name = n.getNodeName();
short type = n.getNodeType();
if (Node.CDATA_SECTION_NODE == type) {
return "');
;
} else {
sb.append("/>").append('\n');
}
} else {
sb.append('>').append('\n');
boolean hasValidChildren = false;
for (int i = 0; i < children.getLength(); i++) {
String childToString = elementToString(children.item(i));
if (!"".equals(childToString)) {
sb.append(childToString);
hasValidChildren = true;
}
}
if (!hasValidChildren && ((textContent = XMLUtil.getTextContent(n)) != null)) {
sb.append(textContent);
}
sb.append("").append(name).append('>');
}
return sb.toString();
}
}