import org.w3c.dom.*;
import org.w3c.dom.ls.*;
import java.io.*;
import java.util.*;
import javax.xml.parsers.*;
public class XmlGenerator {
public static void main(String[] args) throws Exception {
String xml = "ROOT(PARAMS,PARAM1,PARAM2,PARAM3)";
Scanner s = new Scanner(xml);
s.useDelimiter("[(),\\s]");
Document doc = DocumentBuilderFactory.newInstance().newDocumentBuilder()
.newDocument();
Node root = doc.createElement(s.next());
doc.appendChild(root);
Node sheet = doc.createElement(s.next());
root.appendChild(sheet);
while (s.hasNext()) {
Node param = doc.createElement(s.next());
sheet.appendChild(param);
}
System.out.println(XmlGenerator.getStringFromDoc(doc));
}
public static String getStringFromDoc(org.w3c.dom.Document doc) {
DOMImplementationLS domImplementation = (DOMImplementationLS) doc.getImplementation();
LSSerializer lsSerializer = domImplementation.createLSSerializer();
lsSerializer.getDomConfig()
.setParameter("format-pretty-print", Boolean.TRUE);
return lsSerializer.writeToString(doc);
}
}
import org.w3c.dom.ls.*;
import java.io.*;
import java.util.*;
import javax.xml.parsers.*;
public class XmlGenerator {
public static void main(String[] args) throws Exception {
String xml = "ROOT(PARAMS,PARAM1,PARAM2,PARAM3)";
Scanner s = new Scanner(xml);
s.useDelimiter("[(),\\s]");
Document doc = DocumentBuilderFactory.newInstance().newDocumentBuilder()
.newDocument();
Node root = doc.createElement(s.next());
doc.appendChild(root);
Node sheet = doc.createElement(s.next());
root.appendChild(sheet);
while (s.hasNext()) {
Node param = doc.createElement(s.next());
sheet.appendChild(param);
}
System.out.println(XmlGenerator.getStringFromDoc(doc));
}
public static String getStringFromDoc(org.w3c.dom.Document doc) {
DOMImplementationLS domImplementation = (DOMImplementationLS) doc.getImplementation();
LSSerializer lsSerializer = domImplementation.createLSSerializer();
lsSerializer.getDomConfig()
.setParameter("format-pretty-print", Boolean.TRUE);
return lsSerializer.writeToString(doc);
}
}