|
Reading a document from XML file with DOM |
|
|
Since JDOM represent an API building on standard parsing packages, we
can select the way we want the document be loaded from a file.
In order to load a JDOM document via DOM we hav to you DOMBuilder class.
One of its constructors receives a boolean value, which allows to defined
if the document must be validates or not.
Sample below shows how it is easilly to load a JDOM document:
import org.jdom.Document;
import org.jdom.input.DOMBuilder;
/**
* This sample program showing how to load JDOM document
* using DOM builder.
*/
public class Test {
public static void main(String[] args) {
try {
// a builder takes a boolean value meaning validation mode:
DOMBuilder builder = new DOMBuilder(false);
// simply load the document::
Document document = builder.build(new java.io.File("sample.xml"));
// .. do something ...
} 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.