Questions tagged [jdom]

JDOM is an open source library for working with a Java representation of an XML document. JDOM provides a way to represent that document for easy and efficient reading, manipulation, and writing. It has a straightforward API, is a lightweight and fast, and is optimized for the Java programmer.

JDOM is an open source library (hosted on gitub) for working with a Java representation of an XML document. JDOM provides a way to represent that document for easy and efficient reading, manipulation, and writing.

The major features of JDOM that make it easier to use are:

  • it has a straightforward API
  • it is lightweight and fast (relative to other in-memory models)
  • the in-memory model of the document is always well-formed.
  • it is optimized for the Java programmer.
    • It uses standard Java collection structures instead of some other form of containers
    • All Collections are correctly typed using Java Generics
    • It provides simple and high-performance access to XML Parsers and 'outputters'
    • it integrates well with data that is read from, or written to SAX, DOM, and StAX API's

While SAX (and sometimes DOM and StAX) can be used to build JDOM documents, the JDOM API is not like those. Still, JDOM is able to interface well with programs that expect SAX, StAX, or DOM input, or expect JDOM to provide such output.

JDOM is not a wrapper for the W3C's DOM, or another version of DOM. JDOM is a Java-based "document object model" for XML files. JDOM serves the same purpose as DOM, but is easier to use.

JDOM is not an XML parser (like Xerces). It is a document object model that uses XML parsers to build documents. JDOM's SAXBuilder class for example uses the SAX events generated by an XML parser to build a JDOM tree. The default XML parser used by JDOM is the JAXP-selected parser, but JDOM can use nearly any parser.

JDOM 2.0.0 was released in 2012 and introduced full support for Java Generics and an improved XPath interface as well as many other features.

JDOM 1.1.3 is still supported and even runs on Java 1.1.2

485 questions
5
votes
2 answers

JDOM 2 and xpath

Here is the following code excerpted from the Spring-ws manual: public class HolidayEndpoint { private static final String NAMESPACE_URI = "http://mycompany.com/hr/schemas"; private XPath startDateExpression; private XPath…
Thom
  • 14,013
  • 25
  • 105
  • 185
4
votes
2 answers

XML shredding via XSLT in Java

I need to transform large XML files that have a nested (hierarchical) structure of the form Flat XML Hierarchical XML (multiple blocks, some repetitive) Flat XML into a flatter ("shredded") form, with 1 block for each…
PNS
  • 19,295
  • 32
  • 96
  • 143
4
votes
2 answers

How can I compare two Elements for equivalency?

I'm writing unit tests for code which uses JDOM to read and write XML. I therefore need some way to compare the JDOM Element being produced by my code with a reference Element to ensure that they are equivalent (same name, namespace, and…
Ben Blank
  • 54,908
  • 28
  • 127
  • 156
4
votes
4 answers

org.jdom.IllegalAddException: The Content already has an existing parent "root"

I am trying to split a large XML file (500mb) using jDOM (I know I should probably try SAX but ...) but I am getting org.jdom.IllegalAddException: The Content already has an existing parent "root" exception as shown in the code below. sample xml and…
kpr
  • 41
  • 1
  • 1
  • 2
4
votes
3 answers

Remove Element from JDOM document using removeContent()

Given the following scenario, where the xml, Geography.xml looks like -
Swift-Tuttle
  • 485
  • 3
  • 14
  • 25
4
votes
1 answer

JDOM, XPath and Namespace Interactions

I'm having a very frustrating time extracting some elements from a JDOM document using an XPath expression. Here's a sample XML document - I'd like to remove the ItemCost elements from the document altogether, but I'm having trouble getting an XPath…
Bryn Sadler
  • 43
  • 1
  • 7
4
votes
1 answer

JDOMParseException: Error on line -1: Premature end of file

I'm getting that exception when reading an InputStream with JDOM's SAXBuilder's build method: InputStream bais = p_sendXML.getXml().getInputStream(); File myFile = new File(System.getProperty("java.io.tmpdir"),…
pHneutre
  • 1,091
  • 3
  • 12
  • 29
4
votes
1 answer

Converting a List of pojo Class to a Jdom Tree?

I have a POJO class call LEVEL & his class diagramm like this: 0,1 ------------| | | | | \|/ | level-<>------- In other words this: public class Level { private int id; private int label; …
mada
  • 111
  • 4
4
votes
1 answer

create xml with jdom, how to set standalone="no" attribute

When I create a jdom document (Document doc = new Document();), by default I only see version and encoding in the xml header: How can I add the standalone attribute to get:
markus
  • 6,258
  • 13
  • 41
  • 68
3
votes
1 answer

How do I get the child element's attributes using jdom

Im creating application in java using XML. XML-
yashmathur
  • 65
  • 1
  • 3
  • 8
3
votes
3 answers

can't open xml file on android

I am working on an android application in which I want to parse an xml file as a local resource. I use jdom to parse it, but I have a probleme, I can not open the file and I don't know why. The error is at this line : document = builder.build(new…
user1086225
  • 45
  • 1
  • 4
3
votes
3 answers

unknown protocol: c (JDOM a SAXBuilder)

I'm using JDOM with SAXBuilder to parse XML files, and I have a problem with a file which is throwing this error : java.net.MalformedURLException: unknown protocol: c at java.net.URL.(URL.java:574) at java.net.URL.(URL.java:464) …
Wassim AZIRAR
  • 10,823
  • 38
  • 121
  • 174
3
votes
3 answers

JDom working with XPath

I am a newbie to JDom, I try to use XPath to access my xml file. My code is like following: public static void main(String[] args) throws Exception { Document doc = new SAXBuilder().build("file.xml"); XPath x = XPath.newInstance("xpath"); …
Michael
  • 2,075
  • 7
  • 32
  • 46
3
votes
3 answers

XML API for best performance

I have an application that works with a lot of XML data. So, I want to ask you which is the best API to handle XML in java. Today, I'm using W3 and, for performance, I want to migrate to some API. I make XML from 0, a lot of transforms, import into…
jotapdiez
  • 1,456
  • 13
  • 28
3
votes
1 answer

I read XML documents (JDOM), and I get an exception java.lang.NoClassDefFoundError when running it on another PC

This is my first java software... The software works well on my dev machine, but I get that exception on the other (non-dev) machine (both on Windows 10) : java.lang.NoClassDefFoundError: org/jdom2/JDOMException I read that there is something…
Cruxial
  • 41
  • 4
1 2
3
32 33