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

Why was this exception not caught

I have the following code try { xpathInstance = XPath.newInstance(xpathExpr); list = (Text) xpathInstance.selectSingleNode(doc); } catch (JDOMException e) { throw new Exception(e); } I had forgotten to include a library that was a…
ziggy
  • 15,677
  • 67
  • 194
  • 287
3
votes
1 answer

How can I monitor XML parsing in Java (with JDOM)?

I'm developing an app that parses big XML files (over 200k lines, about 4-5 MB), and I would like to monitor the parsing using a progress bar. I'm using JDOM v1.1.1 and SaxBuilder. Anyone knows how to achieve that ? Thanks
3rgo
  • 3,115
  • 7
  • 31
  • 44
3
votes
3 answers

Why getChild() method of JDOM returns null?

I'm doing a project regarding html document manipulation. I want body content from existing html document to modify it into a new html.Now i'm using JDOM. i want to use body element in my coding.For that i used getChild("body") in my coding.But it…
Arun
  • 182
  • 1
  • 2
  • 14
3
votes
1 answer

How to get only XML content from a SOAP response

I have a sample response:
Anurag
  • 723
  • 3
  • 13
  • 31
3
votes
1 answer

Insert blank lines in jdom2 pretty printing

I'm trying to simply add some blank lines to my jdom xml output. I've tried the following without luck: Element root = new Element("root"); root.addContent(new CDATA("\n")); root.addContent(new Text("\n")); I figured the all-whitespace entry was…
Didjit
  • 785
  • 2
  • 8
  • 26
3
votes
4 answers
3
votes
2 answers

How can I create a self closing tag using JDOM

I could find in Jdom api any function to create self closing xml tag like the below. For example, I need to create the following content: ......
chepukha
  • 2,371
  • 3
  • 28
  • 40
3
votes
1 answer

can not create the xml file using jdom

Here is my code: import java.io.FileWriter; import java.io.IOException; import org.jdom2.Attribute; import org.jdom2.Document; import org.jdom2.Element; import org.jdom2.output.Format; import org.jdom2.output.XMLOutputter; try { Element…
marcss
  • 253
  • 2
  • 14
3
votes
4 answers

Parsing xml with dom4j or jdom or anyhow

I wanna read feed entries and I'm just stuck now. Take this for example : https://stackoverflow.com/feeds/question/2084883 lets say I wanna read all the summary node value inside each entry node in document. How do I do that? I've changed many…
ant
  • 22,634
  • 36
  • 132
  • 182
3
votes
1 answer

XML file is not updating using the jdom

following is my java code for reading a xml file and updating some values in it. public static void writeLexicon(String word, String tag) { int newFreq=0; int tagAvailability = 0; int wordAvaialbility = 0; try { if (new…
Chirath
  • 57
  • 1
  • 10
3
votes
2 answers

Parse String to XML Document jdom2

I have a problem. I want to convert the string to a xml document. But this code is throw exception: Exception in thread "main" java.lang.ClassCastException: com.sun.org.apache.xerces.internal.dom.DeferredDocumentImpl cannot be cast to…
viartemev
  • 211
  • 1
  • 4
  • 13
3
votes
2 answers

android exception even though the jdom library is there

The jdom library is there and i have removed and added it again and again to the build path. And, i have cleaned the project as well many times. But still iam getting this error: 04-27 10:51:27.867: W/ActivityThread(530): Application…
Maverick
  • 2,738
  • 24
  • 91
  • 157
2
votes
3 answers

How to insert XHTML into XML

I'm working with JDOM at the moment. I can't think of a solution which what should essentially be an easy problem. I have a valid XHTML string: M&A € How do I insert this into the XML DOM as follows?   M&A
Trent
  • 2,328
  • 3
  • 33
  • 51
2
votes
2 answers

how to convert org.w3c.dom.Document to org.jdom.Document

I need to convert a org.w3c.dom.Document to org.jdom.Document I have tried the following following.. InputStream inputStream = new ByteArrayInputStream(str.getBytes()); Tidy tidy = new Tidy(); tidy.setMakeClean(false); tidy.setShowWarnings(true);…
Komal Goyal
  • 233
  • 5
  • 17
2
votes
3 answers

JDom XML Filtering

I'm trying to count how many certain elements the document has: Iterator processDescendants = doc.getDescendants(new ElementFilter("a")); while(processDescendants.hasNext()) { numPending++; } processDescendants = doc.getDescendants(new…
jn1kk
  • 5,012
  • 2
  • 45
  • 72