New XML Document
In this chapter you will learn:
Start a new XML Document
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
/*from ja v a2 s. c o m*/
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
public class Utils {
public static Document createXmlDocument(String rootName) {
Document document = getXmlDocumentBuilder().newDocument();
Element root = document.createElement(rootName);
document.appendChild(root);
return document;
}
public static DocumentBuilder getXmlDocumentBuilder() {
try {
DocumentBuilderFactory factory;
factory = DocumentBuilderFactory.newInstance();
factory.setNamespaceAware(false);
return factory.newDocumentBuilder();
} catch (Exception e) {
}
return null;
}
}
Next chapter...
What you will learn in the next chapter:
Home » Java Tutorial » XML