HOME

TheInfoList



OR:

JDOM is an
open-source Open source is source code that is made freely available for possible modification and redistribution. Products include permission to use the source code, design documents, or content of the product. The open-source model is a decentralized sof ...
Java Java (; id, Jawa, ; jv, ꦗꦮ; su, ) is one of the Greater Sunda Islands in Indonesia. It is bordered by the Indian Ocean to the south and the Java Sea to the north. With a population of 151.6 million people, Java is the world's List ...
-based document object model for
XML Extensible Markup Language (XML) is a markup language and file format for storing, transmitting, and reconstructing arbitrary data. It defines a set of rules for encoding documents in a format that is both human-readable and machine-readable ...
that was designed specifically for the
Java platform Java is a set of computer software and specifications developed by James Gosling at Sun Microsystems, which was later acquired by the Oracle Corporation, that provides a system for developing application software and deploying it in a cro ...
so that it can take advantage of its language features. JDOM integrates with
Document Object Model The Document Object Model (DOM) is a cross-platform and language-independent interface that treats an XML or HTML document as a tree structure wherein each node is an object representing a part of the document. The DOM represents a document wi ...
(DOM) and
Simple API for XML SAX (Simple API for XML) is an event-driven online algorithm for parsing XML documents, with an API developed by the XML-DEV mailing list. SAX provides a mechanism for reading data from an XML document that is an alternative to that provided by ...
(SAX), supports
XPath XPath (XML Path Language) is an expression language designed to support the query or transformation of XML documents. It was defined by the World Wide Web Consortium (W3C) and can be used to compute values (e.g., strings, numbers, or Boolean v ...
and
XSLT XSLT (Extensible Stylesheet Language Transformations) is a language originally designed for transforming XML documents into other XML documents, or other formats such as HTML for web pages, plain text or XSL Formatting Objects, which may subseque ...
. It uses external parsers to build documents. JDOM was developed by Jason Hunter and Brett McLaughlin starting in March 2000. It has been part of the
Java Community Process The Java Community Process (JCP), established in 1998, is a formalized mechanism that allows interested parties to develop standard technical specifications for Java technology. Anyone can become a JCP Member by filling a form available at thJCP w ...
as JSR 102, though that effort has since been abandoned.


Examples

Suppose the file "foo.xml" contains this XML document: One can parse the XML file into a tree of Java objects with JDOM, like so: SAXBuilder builder = new SAXBuilder(); Document doc = builder.build(new FileInputStream("foo.xml")); Element root = doc.getRootElement(); // root.getName() is "shop" // root.getAttributeValue("name") is "shop for geeks" // root.getAttributeValue("location") is "Tokyo, Japan" // root.getChildren() is a java.util.List object that contains 3 Element objects. In case you do not want to create the document object from any file or any input stream, you can create the document object against the element. Element root = new Element("shop"); // here is the root Document doc = new Document(root); // create a new document with the supplied element as the root As a converse, one can construct a tree of elements, then generate an XML file from it, as in the following example: Element root = new Element("shop"); root.setAttribute("name", "shop for geeks"); root.setAttribute("location", "Tokyo, Japan"); Element item1 = new Element("computer"); item1.setAttribute("name", "iBook"); item1.setAttribute("price", "1200$"); root.addContent(item1); // perform similar steps for other elements XMLOutputter outputter = new XMLOutputter(); outputter.output(new Document(root), new FileOutputStream ("foo2.xml"));


External links

Java (programming language) libraries
Document Object Model The Document Object Model (DOM) is a cross-platform and language-independent interface that treats an XML or HTML document as a tree structure wherein each node is an object representing a part of the document. The DOM represents a document wi ...
XML-based standards {{Compu-lang-stub