|
Reading a document from XML file with SAX |
|
|
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 SAX we hav to you SAXBuilder 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.SAXBuilder;
/**
* This sample program showing how to load JDOM document.
* using SAX builder.
*/
public class Test {
public static void main(String[] args) {
try {
// a builder takes a boolean value meaning validation mode:
SAXBuilder builder = new SAXBuilder(false);
// simply load the document::
Document document = builder.build("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.