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
45
votes
2 answers

How to create a XML object from String in Java?

I am trying to write a code that helps me to create a XML object. For example, I will give a string as input to a function and it will return me a XMLObject. XMLObject convertToXML(String s) {} When I was searching on the net, generally I saw…
Ozer
  • 1,245
  • 4
  • 20
  • 27
31
votes
3 answers

How to convert org.jdom.Document to String

How do I to convert an org.jdom.Document to a String in Java?
Aravind
  • 2,188
  • 4
  • 24
  • 28
20
votes
1 answer

xpath 2.0 for java possible

What package shall I use for XPath? I want wo query for elements and then extract some values around these nodes. Maybe one or more levels higher, some attributes. javax.xml.xpath is XPath 1.0. Is javax.xml.xpath and org.w3c.dom the right way to go,…
Franz Kafka
  • 10,623
  • 20
  • 93
  • 149
17
votes
3 answers

XMLSchema validation on Android

I maintain the JDOM project and I am trying to 'certify' it on Android. Most things work fine, but XML Schema validation is proving problematic... My questions are: Is there a way to do XMLSchema validation on Android? If there is, how? Questions…
rolfl
  • 17,539
  • 7
  • 42
  • 76
15
votes
7 answers

ClassCastException: org.apache.xerces.parsers.XIncludeAwareParserConfiguration cannot be cast to org.apache.xerces.xni.parser.XMLParserConfiguration

I am developing a GWT application in Eclipse and use jdom2 to read some custom xml property files. Following a recent update my application now fails with the above error when trying to read the xml file. The relevant stack trace…
ejoftheweb
  • 301
  • 1
  • 2
  • 10
13
votes
3 answers

Default XML namespace, JDOM, and XPath

I want to use JDOM to read in an XML file, then use XPath to extract data from the JDOM Document. It creates the Document object fine, but when I use XPath to query the Document for a List of elements, I get nothing. My XML document has a default…
Michael
  • 34,873
  • 17
  • 75
  • 109
13
votes
5 answers

Performing complicated XPath queries in Scala

What's the simplest API to use in scala to perform the following XPath queries on a document? //s:Annotation[@type='attitude']/s:Content/s:Parameter[@role='type' and not(text())] //s:Annotation[s:Content/s:Parameter[@role='id' and…
Ken Bloom
  • 57,498
  • 14
  • 111
  • 168
12
votes
2 answers

What is best way to change one value in XML files in Java?

I have an XML file and I know the node name I need to change the value for. The nodename is ipAddress. I can use JDOM, get document, get node and change the value and write it or I can write an XSLT file. The code changing value goes from Java, so…
yart
  • 7,515
  • 12
  • 37
  • 37
12
votes
2 answers

How to convert String having contents in XML format into JDom document

How convert String having contents in XML format into JDom document. i am trying with below code: String docString = txtEditor.getDocumentProvider().getDocument( txtEditor.getEditorInput()).get(); SAXBuilder sb= new SAXBuilder(); doc =…
User_86
  • 265
  • 1
  • 4
  • 13
8
votes
1 answer

JDOM Is using too much memory

I have an application that uses XmlUnit to get differences from two XML files. But the problem is that XmlUnit uses JDOM. My xml Files are ~1GB big! It take too much RAM to store those xml in a JDOM document. I have tried to use SlimJDOMFactory…
JajaDrinker
  • 652
  • 6
  • 15
8
votes
1 answer

InstantiationException in hadoop map reduce program

I am new to Hadoop framework. I was trying to write a program which reads XML file from hdfs, parses it using JDOM and sends it to a database. The following is the Java file package JDOMprs; import java.io.IOException; import…
Ashish Banerjee
  • 221
  • 1
  • 3
  • 8
7
votes
2 answers

How to parse an XML file containing BOM?

I want to parse an XML file from URL using JDOM. But when trying this: SAXBuilder builder = new SAXBuilder(); builder.build(aUrl); I get this exception: Invalid byte 1 of 1-byte UTF-8 sequence. I thought this might be the BOM issue. So I checked…
doctrey
  • 1,227
  • 1
  • 12
  • 25
7
votes
7 answers

How to get node contents from JDOM

I'm writing an application in java using import org.jdom.*; My XML is valid,but sometimes it contains HTML tags. For example, something like this: Anatomy & Physiology
jeph perro
  • 6,242
  • 26
  • 90
  • 124
7
votes
1 answer

namespaces and JDOM

My current code is printing out the xml like this : x3000 - a very fast train NULL
Sembrano
  • 1,127
  • 4
  • 18
  • 28
7
votes
9 answers

Java out of memory Exception

I am running a Java Web Application in Tomcat. The application uses Quartz framework to schedule the cron job at regular intervals. This cron job involves parsing a 4+ MB xml file, which I am doing using JDOM API. The xml file contains around 3600…
Amit
  • 435
  • 2
  • 8
  • 16
1
2 3
32 33