fbpx
Wikipedia

JDOM

JDOM is an open-source Java-based document object model for XML that was designed specifically for the Java platform so that it can take advantage of its language features. JDOM integrates with Document Object Model (DOM) and Simple API for XML (SAX), supports XPath and XSLT. It uses external parsers to build documents. JDOM was developed by Jason Hunter and Brett McLaughlin starting in March 2000. It has been part of the Java Community Process as JSR 102, though that effort has since been abandoned.

JDOM
Stable release
2.0.6.1 / December 9, 2021 (2021-12-09)
Repository
  • github.com/hunterhacker/jdom
Written inJava
Operating systemCross-platform
TypeXML binding
LicenseSimilar to Apache License
Websitejdom.org
JDOM in LePUS3
JDOM factories in LePUS3

Examples edit

Suppose the file "foo.xml" contains this XML document:

<shop name="shop for geeks" location="Tokyo, Japan">  <computer name="iBook" price="1200$" />  <comic_book name="Dragon Ball vol 1" price="9$" />  <geekyness_of_shop price="priceless" /> </shop> 

One can parse the XML file into a tree of Java objects with JDOM, like so:

SAXBuilder builder = new SAXBuilder(); Document doc = builder.build(new FileInputStream("foo.xml")); Element root = doc.getRootElement(); // root.getName() is "shop" // root.getAttributeValue("name") is "shop for geeks" // root.getAttributeValue("location") is "Tokyo, Japan" // root.getChildren() is a java.util.List object that contains 3 Element objects. 

In case you do not want to create the document object from any file or any input stream, you can create the document object against the element.

Element root = new Element("shop"); // here <shop></shop> is the root Document doc = new Document(root); // create a new document with the supplied element as the root 

As a converse, one can construct a tree of elements, then generate an XML file from it, as in the following example:

Element root = new Element("shop"); root.setAttribute("name", "shop for geeks"); root.setAttribute("location", "Tokyo, Japan"); Element item1 = new Element("computer"); item1.setAttribute("name", "iBook"); item1.setAttribute("price", "1200$"); root.addContent(item1); // perform similar steps for other elements XMLOutputter outputter = new XMLOutputter(); outputter.output(new Document(root), new FileOutputStream ("foo2.xml")); 

External links edit

Official website  


jdom, this, article, contains, instructions, advice, content, please, help, rewrite, content, that, more, encyclopedic, move, wikiversity, wikibooks, wikivoyage, 2011, open, source, java, based, document, object, model, that, designed, specifically, java, plat. This article contains instructions advice or how to content Please help rewrite the content so that it is more encyclopedic or move it to Wikiversity Wikibooks or Wikivoyage May 2011 JDOM is an open source Java based document object model for XML that was designed specifically for the Java platform so that it can take advantage of its language features JDOM integrates with Document Object Model DOM and Simple API for XML SAX supports XPath and XSLT It uses external parsers to build documents JDOM was developed by Jason Hunter and Brett McLaughlin starting in March 2000 It has been part of the Java Community Process as JSR 102 though that effort has since been abandoned JDOMStable release2 0 6 1 December 9 2021 2021 12 09 Repositorygithub wbr com wbr hunterhacker wbr jdomWritten inJavaOperating systemCross platformTypeXML bindingLicenseSimilar to Apache LicenseWebsitejdom wbr orgJDOM in LePUS3JDOM factories in LePUS3Examples editSuppose the file foo xml contains this XML document lt shop name shop for geeks location Tokyo Japan gt lt computer name iBook price 1200 gt lt comic book name Dragon Ball vol 1 price 9 gt lt geekyness of shop price priceless gt lt shop gt One can parse the XML file into a tree of Java objects with JDOM like so SAXBuilder builder new SAXBuilder Document doc builder build new FileInputStream foo xml Element root doc getRootElement root getName is shop root getAttributeValue name is shop for geeks root getAttributeValue location is Tokyo Japan root getChildren is a java util List object that contains 3 Element objects In case you do not want to create the document object from any file or any input stream you can create the document object against the element Element root new Element shop here lt shop gt lt shop gt is the root Document doc new Document root create a new document with the supplied element as the root As a converse one can construct a tree of elements then generate an XML file from it as in the following example Element root new Element shop root setAttribute name shop for geeks root setAttribute location Tokyo Japan Element item1 new Element computer item1 setAttribute name iBook item1 setAttribute price 1200 root addContent item1 perform similar steps for other elements XMLOutputter outputter new XMLOutputter outputter output new Document root new FileOutputStream foo2 xml External links editOfficial website nbsp nbsp This programming language related article is a stub You can help Wikipedia by expanding it vte Retrieved from https en wikipedia org w index php title JDOM amp oldid 1066987764, wikipedia, wiki, book, books, library,

article

, read, download, free, free download, mp3, video, mp4, 3gp, jpg, jpeg, gif, png, picture, music, song, movie, book, game, games.