Java XML – JDOM2 – Filters

JDOM2 has three methods that accepts Filters while obtaining data. The three methods are &ltE extends Content&gt List&ltE&gt getContent(Filter&ltE&gt filter); &ltE extends Content&gt List&ltE&gt removeContent(Filter&ltE&gt filter); &ltE extends Content&gt IteratorIterable&ltE&gt getDescendants(Filter&ltE&gt filter); Filters are also extensively used in the JDOM2 XPath API, especially to ‘coerce the xpath result data in to the generic-typed results’. See … Read more

Java XML – JDOM2 – StAXBuilder

In the previous examples we saw how to bulid a JDOM2 document from w3c Document. We also saw how to build a JDOM2 Document using a SAXBuilder. In this example we look at how to create a JDOM2 document using a StAXEventBuilder or a StAXStreamBuilder. StAXEventBuilder StAXEventBuilder builds a JDOM2 document using a StAX based … Read more

Java XML – JDOM2 – DOMBuilder

Buliding JDOM2 documents from w3c DOM JDOM2 provides a DOMBuilder that can be used to build a JDOM2 Document from a org.w3c.dom.Document. If there are namespace declarations in the xml document then make sure that while parsing the XML document the setNamespaceAware method of the DocumentBuilderFactory is set to true. Before we look at an … Read more

Java XML – JDOM2 – SAXBuilder

The Plot SAXBuilder provides methods to build JDOM2 Documents using a third party SAX Parser. It has three parts A SAX Parser to parse the XML document. The default Parser is JAXP. A SAX Handler to handle SAX events. A JDOM2 Factory to build the JDOM2 Document This tutorial introduces the various classes that form … Read more

Java XML – JDOM2 – SAXBuilder XSD Validating

In the earlier tutorials we saw how to build a JDOM2 document using SAXBuilder. We also saw how to validate the document using DTD while using the SAXBuilder. In this tutorial we look at how to use the SAXBuilder that validates against an XSD. The example below shows how to use an internally defined XSD. … Read more

Java XML – JDOM2 – SAXBuilder DTD Validating

In this tutorial we look at how to use SAXBuilder to create a JDOM2 Document such that the SAXBuilder validates the XML using the DTD before creating the JDOM2 document. If you are looking for a way to create JDOM2 Document using the SAXBuilder but without any validation then this tutorial explains just that. We … Read more

Java XML – JDOM2 – SAXBuilder Example

In this tutorial we look at how to build a JDOM2 using a SAXBuilder. To understand how SAXBuilder works and how to configure it look at this tutorial. The example below demonstrates the following Building a JDOM2 document using a SAXBuilder. Obtaining the DOCTYPE of the document. Obtaining the root element of the document Obtaining … Read more

Java XML – Example JDOM2 Usage

Building JDOM2 Document In this tutorial we look at an example of how to build and navigate through a JDOM2 document from an XML source (in this case, a BBC News “Technology” RSS feed). We first use the org.jdom2.input.SAXBuilder class to create the JDOM2 document from the source (more details and options on the SAXBuilder … Read more

Java XML – JDOM2 – Packages

In this tutorial we explore the package structure and important classes for Jdom2. org.jdom2 This package contains the core classes that represent the XML components. Document – Represents the complete XML document. It provides access to the root element and also the docType. DocType – Represents an XML DOCTYPE. Element – Represents an XML element. … Read more

Java XML – JDOM2 – Introduction

What is JDOM JDOM is an in-memory XML model that can be used to read, write, create and modify XML Documents. JDOM is similar to DOM in that they both provide an in-memory XML document model, but while DOM is designed to work the same in multiple languages (C, C++, ECMAScript, Java, JScript, Lingo, PHP, … Read more