JDOM

Last updated
JDOM
Stable release
2.0.6 / February 15, 2015 (2015-02-15)
Repository OOjs UI icon edit-ltr-progressive.svg
Written in Java
Operating system Cross-platform
Type XML binding
License Similar to Apache License
Website jdom.org
JDOM in LePUS3 Jdom.png
JDOM in LePUS3
JDOM factories in LePUS3 Jdom-factories.png
JDOM factories in LePUS3

JDOM is an open-source Java-based document object model for XML that was designed specifically for the Java platform so that it can take advantage of its language features. JDOM integrates with Document Object Model (DOM) and Simple API for XML (SAX), supports XPath and XSLT. 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 as JSR 102, though that effort has since been abandoned.

Examples

Suppose the file "foo.xml" contains this XML document:

<shopname="shop for geeks"location="Tokyo, Japan"><computername="iBook"price="1200$"/><comic_bookname="Dragon Ball vol 1"price="9$"/><geekyness_of_shopprice="priceless"/></shop>

One can parse the XML file into a tree of Java objects with JDOM, like so:

SAXBuilderbuilder=newSAXBuilder();Documentdoc=builder.build(newFileInputStream("foo.xml"));Elementroot=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.

Elementroot=newElement("shop");// here <shop></shop> is the rootDocumentdoc=newDocument(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:

Elementroot=newElement("shop");root.setAttribute("name","shop for geeks");root.setAttribute("location","Tokyo, Japan");Elementitem1=newElement("computer");item1.setAttribute("name","iBook");item1.setAttribute("price","1200$");root.addContent(item1);// perform similar steps for other elementsXMLOutputteroutputter=newXMLOutputter();outputter.output(newDocument(root),newFileOutputStream("foo2.xml"));

Official website OOjs UI icon edit-ltr-progressive.svg


Related Research Articles

A document type definition (DTD) is a set of markup declarations that define a document type for an SGML-family markup language.

Document Object Model Convention for representing and interacting with objects in HTML, XHTML and XML documents

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 with a logical tree. Each branch of the tree ends in a node, and each node contains objects. DOM methods allow programmatic access to the tree; with them one can change the structure, style or content of a document. Nodes can have event handlers attached to them. Once an event is triggered, the event handlers get executed.

In computing, a namespace is a set of symbols (names) that are used to identify and refer to objects of various kinds. A namespace ensures that all of a given set of objects have unique names so that they can be easily identified.

Extensible Markup Language (XML) is a markup language that defines a set of rules for encoding documents in a format that is both human-readable and machine-readable. The World Wide Web Consortium's XML 1.0 Specification of 1998 and several other related specifications—all of them free open standards—define XML.

XSLT is a language 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 subsequently be converted to other formats, such as PDF, PostScript and PNG. XSLT 1.0 is widely supported in modern web browsers.

Java Platform, Standard Edition is a computing platform for development and deployment of portable code for desktop and server environments. Java SE was formerly known as Java 2 Platform, Standard Edition (J2SE).

In computing, the Java API for XML Processing, or JAXP, one of the Java XML Application programming interfaces (API)s, provides the capability of validating and parsing XML documents. It has three basic parsing interfaces:

SAX 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 the Document Object Model (DOM). Where the DOM operates on the document as a whole—building the full abstract syntax tree of an XML document for convenience of the user—SAX parsers operate on each piece of the XML document sequentially, issuing parsing events while making a single pass through the input stream.

An HTML element is a type of HTML document component, one of several types of HTML nodes. HTML document is composed of a tree of simple HTML nodes, such as text nodes, and HTML elements, which add semantics and formatting to parts of document. Each element can have HTML attributes specified. Elements can also have content, including other elements and text.

Java syntax

The syntax of Java refers to the set of rules defining how a Java program is written and interpreted.

The term CDATA, meaning character data, is used for distinct, but related, purposes in the markup languages SGML and XML. The term indicates that a certain portion of the document is general character data, rather than non-character data or character data with a more specific, limited structure.

Streaming API for XML (StAX) is an application programming interface (API) to read and write XML documents, originating from the Java programming language community.

XML documents have a hierarchical structure and can conceptually be interpreted as a tree structure, called an XML tree.

Oxygen XML Editor multi-platform XML editor, XSLT/XQuery debugger and profiler

The Oxygen XML Editor is a multi-platform XML editor, XSLT/XQuery debugger and profiler with Unicode support. It is a Java application, so it can run in Windows, Mac OS X, and Linux. It also has a version that can run as an Eclipse plugin.

In computer science, marshalling or marshaling is the process of transforming the memory representation of an object to a data format suitable for storage or transmission, and it is typically used when data must be moved between different parts of a computer program or from one program to another. Marshalling is similar to serialization and is used to communicate to remote objects with an object, in this case a serialized object. It simplifies complex communication, using composite objects in order to communicate instead of primitives. The inverse of marshalling is called unmarshalling.

XPath is a query language for selecting nodes from an XML document. In addition, XPath may be used to compute values from the content of an XML document. XPath was defined by the World Wide Web Consortium (W3C).

Virtual Token Descriptor for eXtensible Markup Language (VTD-XML) refers to a collection of cross-platform XML processing technologies centered on a non-extractive XML, "document-centric" parsing technique called Virtual Token Descriptor (VTD). Depending on the perspective, VTD-XML can be viewed as one of the following:

Google Apps Script cloud based scripting language for light-weight application development

Apps Script is a scripting platform developed by Google for light-weight application development in the G Suite platform. Google Apps Script was initially developed by Mike Harm as a side project whilst working as a developer on Google Sheets. Google Apps Script was first publicly announced in May 2009 when a beta testing program was announced by Jonathan Rochelle, then Product Manager, Google Docs. In August 2009 Google Apps Script was subsequently made available to all Google Apps Premier and Education Edition customers. It is based on JavaScript 1.6, but also includes some portions of 1.7 and 1.8 and a subset of the ECMAScript 5 API. Apps Script projects run server-side on Google's infrastructure. According to Google, Apps Script "provides easy ways to automate tasks across Google products and third party services." Apps Script is also the tool that powers the add-ons for Google Docs, Sheets and Slides.

LibSBML is an open-source software library that provides an application programming interface (API) for the SBML format. The libSBML library can be embedded in a software application or used in a web servlet as part of the application or servlet's implementation of support for reading, writing, and manipulating SBML documents and data streams. The core of libSBML is written in ISO standard C++; the library provides API for many programming languages via interfaces generated with the help of SWIG.

Castor is a data binding framework for Java with some features like Java to Java-to-XML binding, Java-to-SQL persistence, paths between Java objects, XML documents, relational tables, etc. Castor is one of the oldest data binding projects.