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

What's the difference of JAXP, JDOM, DOM4J,and XERCES?

What is the difference of them? It is said that JAXP is only a API Specification, JDOM and DOM4J realized it, is it right? And all of them need a XML parser, just like XERCES, is it right? thanks in advance!
Y.L.
  • 1,274
  • 6
  • 23
  • 39
6
votes
3 answers

Namespaces (Default) in JDOM

I am trying to produce a XML document using the newest JDOM package. I'm having trouble with the root element and the namespaces. I need to produce this root element:
jn1kk
  • 5,012
  • 2
  • 45
  • 72
6
votes
1 answer

Parsing malformed/incomplete/invalid XML files

I have a process that parses an XML file using JDOM and xpath to parse the file as shown below: private static SAXBuilder builder = null; private static Document doc = null; private static XPath xpathInstance …
ziggy
  • 15,677
  • 67
  • 194
  • 287
6
votes
1 answer

Format XML, one attribute per line, with JDom

I use JDom for XML parsing / formatting. I would like long lines of attributes to be split into several lines. Like : Into : According to the JDom…
Raphael Jolivet
  • 3,940
  • 5
  • 36
  • 56
6
votes
1 answer

Document declares separate empty namespace rendering NamespaceAware results useless

I'm trying to perform some retrieval queries on a "correct" pom.xml used by maven. For that I use basic XPath queries from JDOM. Unfortunately the queries do not return any results (and neither do simple descendant filters). I'm reasonably sure that…
Vogel612
  • 5,620
  • 5
  • 48
  • 73
6
votes
4 answers

How can I get JDOM/XPath to ignore namespaces?

I need to process an XML DOM, preferably with JDOM, where I can do XPath search on nodes. I know the node names or paths, but I want to ignore namespaces completely because sometimes the document comes with namespaces, sometimes without, and I can't…
AdSR
  • 2,097
  • 3
  • 15
  • 9
5
votes
2 answers

getting grandchildren from xml in java

I need to print out the contents of an xml file into some txt file. Here is a sample of the type of xml i want to print out: SOMEGUY SOME DATE
Aelfhere
  • 171
  • 2
  • 12
5
votes
3 answers

How to retrieve an Element mixed children as text (JDOM)

I have an XML like the following: This value must be bigger than the other. Using JDOM, I can get the following text structures: Document d = new SAXBuilder().build( new StringReader( s )…
st.never
  • 11,723
  • 4
  • 20
  • 21
5
votes
1 answer

Using JDOM to Parse XML file with external DTD that has not been declared in the XML file

In my XML file I have some entities such as ’ So I have created a DTD tag for my XML document to define these entities. Below is the Java code used to read the XML file. SAXBuilder builder = new SAXBuilder(); URL url = new…
anonymous
  • 2,294
  • 5
  • 23
  • 27
5
votes
2 answers

How can I do type-safe Xpath queries in Java?

I'm currently using JDOM for doing some simple XML parsing, and it seems like nothing's type safe - I had a similar issue with using the built-in Java DOM parser, just with lots more API to wade through. For example, XPath.selectNodes takes an…
decitrig
  • 778
  • 5
  • 23
5
votes
1 answer

How to disable escaping using XMLOutputter

I use XMLOutputter to write xml file to use it then in android. When the file is written, string Text is written as <u>Text<u> I read "Text" from database and…
5
votes
3 answers

adding content to existing xml with jdom

package xml.dierenshop.flaming.v1; import org.jdom2.Document; import org.jdom2.Element; import org.jdom2.output.XMLOutputter; import org.jdom2.output.Format; import java.io.FileWriter; import java.io.IOException; public class Writer { public…
Boyen
  • 1,429
  • 2
  • 15
  • 22
5
votes
3 answers

java.lang.ClassNotFoundException: org.jdom.JDOMException

I am getting the following error message when trying to load an rss page: Feb 16, 2013 9:08:44 PM org.apache.catalina.core.StandardWrapperValve invoke SEVERE: Servlet.service() for servlet [news-feed] in context with path [/publisher] threw…
CodeMed
  • 9,527
  • 70
  • 212
  • 364
5
votes
2 answers

JDOM, umaluts and UTF-8

I have issue with using utf-8 with JDOM parser. My code won't write encoded in utf-8. Here's code: import java.io.FileWriter; import java.io.IOException; import org.jdom2.Element; import org.jdom2.output.Format; import…
user696847
  • 469
  • 2
  • 7
  • 16
5
votes
2 answers

How to get an element by the value of its attribute using JDOM?

I have a xml file like the following one: http://www.mywebsite.com/admins?cat=writer
moorara
  • 3,897
  • 10
  • 47
  • 60
1
2
3
32 33