|
Creating a new document with JDOM |
|
|
JDOM provides a convenient interface for dynamic XML-document creation.
Here we require no implementation-drivers (like in SAX or DOM); and we manage
explicit Java classes rather than interfaces.
In order to create new XML-contents with JDOM we just have to define its root
element before and then instantiate a document for it. It is shown in sample below:
import org.jdom.DocType;
import org.jdom.Document;
import org.jdom.Element;
/**
* This sample program showing how to create new JDOM document.
*/
public class Test {
public static void main(String[] args) {
try {
// first we have to create a document element:
Element order = new Element("purchase-order");
// ... the we can define a document:
Document document = new Document(order);
// we can event compose and insert our document type:
DocType type = new DocType("purchase-order");
document.setDocType(type);
// .. create some other contents ...
} catch (Exception ex) {
ex.printStackTrace();
}
}
}
|
Related Tips
|
Page 1 of 0 ( 0 comments )
You can share your information about this topic using the form below!
Please do not post your questions with this form! Thanks.