JDOM

JDOM

Infobox_Software
=
caption =
developer =
latest_release_version = 1.1
latest_release_date = 13.11.2007
operating_system = Cross-platform
programming language = Java
genre = XML
license = OpenSource (apache like)
website = http://jdom.org

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. The name JDOM is a pseudo-acronym for Java Document Object Model.

Examples

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

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 don't 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 is the rootDocument doc = new Document(root);

As a converse, one can construct a tree of elements, then generate a XML file from it, like:

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);// do the similar for other elementsXMLOutputter outputter = new XMLOutputter();outputter.output(new Document(root), new FileOutputStream ("foo2.xml"));

External links

* [http://www.jdom.org/ JDOM home page]
* [http://www-128.ibm.com/developerworks/java/library/j-jdom/ Simplify XML Programming with JDOM]


Wikimedia Foundation. 2010.

Игры ⚽ Нужен реферат?

Look at other dictionaries:

  • JDOM — Aktuelle Version 1.1.1 (26. Juli 2009) Betriebssystem Cross platform Kategorie XML Lizenz OpenSource (ähnlich der Apache Lizenz) …   Deutsch Wikipedia

  • JDOM — Тип XML Операционная система Кроссплатформенное программное обеспечение Последняя версия 2.0.4 (8 ноября 2012) Лицензия Apache License Сайт http://jd …   Википедия

  • JDOM — Desarrollador JDOM Project http://www.jdom.org Información general Última versión estable 1.1 18 de noviembre de 2007 …   Wikipedia Español

  • JDOM — Java Document Object Model http://www.jdom.org/ …   Acronyms

  • JDOM — Java Document Object Model (http://www.jdom.org/) …   Acronyms von A bis Z

  • Dom4J — ist eine in der Programmiersprache Java geschriebene Open Source Programmierschnittstelle (API) für den Zugriff und die Verarbeitung von XML Dokumenten. Weitere Java DOM Implementierungen Jdom liegt seit November 2007 in der Version 1.1 vor und… …   Deutsch Wikipedia

  • Dom4j — ist eine in der Programmiersprache Java geschriebene Open Source Programmierschnittstelle (API) für den Zugriff und die Verarbeitung von XML Dokumenten. Weitere Java DOM Implementierungen Jdom liegt seit November 2007 in der Version 1.1 vor und… …   Deutsch Wikipedia

  • dom4j — Aktuelle Version 1.6.1 (16. Mai 2005) Betriebssystem plattformunabhängig Programmier­sprache Java Kategorie XML Framework Lizenz …   Deutsch Wikipedia

  • Document object model — DOM Knotenbaum einer Webseite Das Document Object Model (DOM) ist eine Spezifikation einer Schnittstelle für den Zugriff auf HTML oder XML Dokumente. Sie wird vom World Wide Web Consortium definiert. Eine Implementierung, die dieser Spezifikation …   Deutsch Wikipedia

  • .xml — Extensible Markup Language Extensible Markup Language Extension de fichier .xml Type MIME application/xml, text/xml Développé par World Wide Web Consortium Type de format …   Wikipédia en Français

Share the article and excerpts

Direct link
Do a right-click on the link above
and select “Copy Link”