Tarafından geliştirildi | Jason Hunter, Brett McLaughlin ve Rolf Lear |
---|---|
İlk versiyon | 1 Mart 2000 |
Son sürüm | 2.0.4 (8 Kasım 2012 ) |
Depozito | github.com/hunterhacker/jdom |
Yazılmış | Java |
Çevre | Çapraz platform |
Tür | XML |
Lisans | Apache lisansı |
İnternet sitesi | http://jdom.org |
JDOM (İngilizce Java Belge Nesne Modeli'nin kısaltması), Java'da XML dosyalarını işlemek için açık kaynaklı bir kitaplıktır . DOM ve SAX'i entegre eder ve XPath ve XSLT'yi destekler . Belgeleri oluşturmak için harici ayrıştırmayı kullanır .
Ya "store.xml" dosyası:
<magasin nom="magasin pour geeks" localisation="Tokyo, Japon"> <ordinateur nom="iBook" prix="1200" /> <manga nom="Dragon Ball vol 1" prix="9" /> </magasin>Belgeyi JDOM ile bir Java nesne ağacına ayrıştırmak mümkündür:
import java.io.*; import org.jdom.*; import org.jdom.input.*; import org.jdom.output.*; SAXBuilder builder = new SAXBuilder(); Document doc = builder.build(new FileInputStream("magasin.xml")); Element root = doc.getRootElement(); System.out.println(root.getName()); // renvoie "magasin" System.out.println(root.getAttributeValue("nom")); // "magasin pour geeks" System.out.println(root.getAttributeValue("localisation")); // "Tokyo, Japon" System.out.println(root.getChildren()); // java.util.List de deux objetsBelge nesnesini dosya veya giriş verileri olmadan oluşturmak için:
Element root = new Element("magasin"); // définit la racine comme : <magasin></magasin> Document doc = new Document(root);Tersine, bir XML dosyası oluşturan bir öğe ağacı oluşturabiliriz:
Element root = new Element("magasin"); root.setAttribute("nom", "magasin pour geeks"); root.setAttribute("localisation", "Tokyo, Japon"); Element item1 = new Element("ordinateur"); item1.setAttribute("nom", "iBook"); item1.setAttribute("prix", "1200"); root.addContent(item1); XMLOutputter outputter = new XMLOutputter(); outputter.output(new Document(root), new FileOutputStream ("magasin2.xml")); // crée la même chose que magasin.xml à partir du Java