Difference between revisions of "Load a XML document"

From CodeCodex

Line 31: Line 31:
[[Category:Objective Caml]]

Revision as of 19:36, 31 July 2006




This code requires JDOM, an external library, to run.
 * 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 code requires XML-Light, an external library, to run.

This is a one-liner in OCaml:

# Xml.parse_file "test.xml";;
- : Xml.xml = Xml.Element ("foo", [], [Xml.PCData "bar"])