IBM®
跳转到主要内容
    中国 [选择]    使用条款
 
 
Select a scope: Search for:    
    首页    产品    服务与解决方案     支持与下载    个性化服务    
跳转到主要内容

developerWorks 中国  >  Java technology  >

Simplify XML programming with JDOM

This open-source API makes XML document manipulation easy for Java developers

developerWorks


Building a JDOM document
        
// Create the root element
Element carElement = new Element("car");
//create the document
Document myDocument = new Document(carElement);
//add an attribute to the root element
carElement.addAttribute(new Attribute("vin", "123fhg5869705iop90"));
//add a comment
carElement.addContent(new Comment("Description of a car"));
//add some child elements
Element make = new Element("make");
make.addContent("Toyota");
carElement.addContent(make);
//add some more elements
carElement.addContent(new Element("model").addContent("Celica"));
carElement.addContent(new Element("year").addContent("1997"));
carElement.addContent(new Element("color").addContent("green"));
carElement.addContent(new Element("license")
        .addContent("1ABC234").addAttribute("state", "CA"));
        
        
      

Return to the article.

    关于 IBM 隐私条约 联系 IBM 使用条款