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

JDOM Element creation

I am new to JDOM, and am having trouble creating a document. The problem is that I want to be able to add Elements that do NOT have the "xmlns" attribute. I am using JDOM 1.1 All of the examples I have found show the output without the "xmlns". …
mitchmcc
  • 369
  • 3
  • 5
  • 18
2
votes
2 answers

Set namespace using jdom

I would like have this format in xml: .... I am using the following code: Namespace ns= Namespace.getNamespace("url"); Namespace ns2 = Namespace.getNamespace("ns2",…
haner
  • 21
  • 1
  • 1
  • 3
2
votes
1 answer

Add jsp directive from server side

i wanna do something like Document dom = new Document(); Element ele = new Element("jsp:include"); dom.setRootElement(ele); but its throwing error i am using jdom for getting dom(org.jdom.Document, org.jdom.Element) whats wrong in doing this
Varun
  • 5,001
  • 12
  • 54
  • 85
2
votes
3 answers

How can I use jdom to check wether an element is present in a file or not

I have an XML file like this: ..... How can I check if the File contains Achild element or not..? final DocumentBuilderFactory factory =…
Saurabh Kumar
  • 16,353
  • 49
  • 133
  • 212
2
votes
3 answers

JAVA code snippet to replace single quote(') to double quote in whole XML file

I have a XML file having nested tags. We can use DOM, JDOM parser I want to replace inside the string of all tag from single quote(') to double quote in whole XML file. tag can be nested inside tags also. I want some for loop which looks for all …
2
votes
3 answers

MalformedURL Exception getting while reading the file

I copied one code from my weblogic 8.1 environment and copy in my new environment weblogic 10.3.4. following peace of code is working in my 8.1 env. and when I am using the same code its giving me folowing exception. code String…
Pedantic
  • 1,368
  • 10
  • 39
  • 70
2
votes
1 answer

Error XPATH KML JDOM

I am trying to read a KML with JDOM(XPATH). The error is not caught by Exceptions, only with mouse over code at line XPath.newInstance("//Kml/Document/Placemark/LookAt"); The error I am seeing…
Thiago C. S Ventura
  • 2,448
  • 1
  • 29
  • 43
2
votes
1 answer

How to generate xml file with an existing dtd for sample of data using Java

I have some data stored in : HashMap listOfPoints = new HashMap<>(); Where key contains pair (x,y). I have defined also my dtd file called generated.dtd which contains my structure :
Gismail
  • 89
  • 10
2
votes
1 answer

XPath doesn't return expected values

I have XML document that I parse with jDOM and then try to take all nodes that satisfies XPath expression, but XPath always returns no elements. Here is my XML file: