Load a XML document
From CodeCodex
[edit] Implementations
import org.jdom.*;
import org.jdom.input.*;
import java.io.*;
/**
* Loads a JDOM XML Document
* @param f The file representing the Document
* @return The loaded Document or null if file was not well-formed XML or not found
*/
public static Document loadXml(File f) {
Document d = new Document();
SAXBuilder saxb = new SAXBuilder();
try {
d = saxb.build(f);
} catch (Exception e) {
System.out.println("Error loading "+ f.toString() +". Error: "+e.getMessage());
return null;
}
return d;
}
This is a one-liner in OCaml:
# Xml.parse_file "test.xml";;
- : Xml.xml = Xml.Element ("foo", [], [Xml.PCData "bar"])