Listing 2: XOMCreateXMLDocument.java
import nu.xom.Element;
import nu.xom.Document;
import nu.xom.Attribute;
import nu.xom.DocType;
public class XOMCreateXMLDocument {
public static void main(String[] args) {
final String register = "http://www.airwings.org/register/";
Element root = new Element("company");
Element companyname = new Element("company-name");
companyname.appendChild("AirWings");
root.appendChild(companyname);
Element availableaircrafts = new Element("available-aircrafts");
Element aircraft = new Element("aircraft");
Attribute name = new Attribute("name","Shark");
Attribute code = new Attribute("code","09786554");
Attribute id = new Attribute("id","1211222");
aircraft.addAttribute(name);
aircraft.addAttribute(code);
aircraft.addAttribute(id);
Element flyfrom = new Element("fly-from");
Attribute year = new Attribute("year","2005");
flyfrom.addAttribute(year);
Element price = new Element("price");
Attribute ammount = new Attribute("ammount","250000.00");
Attribute currency = new Attribute("currency","$");
price.addAttribute(ammount);
price.addAttribute(currency);
availableaircrafts.appendChild(aircraft);
availableaircrafts.appendChild(flyfrom);
availableaircrafts.appendChild(price);
root.appendChild(availableaircrafts);
Element photo = new Element("photo");
Element image = new Element("image");
Attribute src = new Attribute("src","file:///C://Data_Local//pictures//Shark.bmp");
Attribute alt = new Attribute("alt","Shark Aircraft Gallery");
Attribute type = new Attribute("type","image/bmp");
image.addAttribute(src);
image.addAttribute(alt);
image.addAttribute(type);
photo.appendChild(image);
availableaircrafts.appendChild(photo);
Element companydetails = new Element("mc:company-details",register);
companydetails.appendChild("These information are confidential:");
Element yourcompanyname = new Element("mc:company-pib",register);
yourcompanyname.appendChild("$5.000.000");
Element licenseid = new Element("mc:license-id",register);
licenseid.appendChild("J-1490-897AAS");
Element bankaccount = new Element("mc:bank-account",register);
bankaccount.appendChild("RO65575656546544745");
companydetails.appendChild(yourcompanyname);
companydetails.appendChild(licenseid);
companydetails.appendChild(bankaccount);
root.appendChild(companydetails);
Document doc = new Document(root);
DocType doctype = new DocType("company", "AirWings_xml.dtd");
doc.insertChild(doctype, 0);
String result = doc.toXML();
System.out.println(result);
}
}
New on the Java Boutique:
New Review:
Time Management Made Easy with the Quartz Enterprise Job Scheduler
Why not just use the Java timer API? This open source scheduling
API boasts simplicity, ease-of-integration, a well-rounded feature
set, and it's free!
New Applet:
Reverse Complement
Reverse Complement is a simple applet that converts DNA or RNA
sequences into three useful formats.
Elsewhere on internet.com:
WebDeveloper Java
Lots of Java information on webdeveloper.com
WDVL Java
Thorough Java resource at the Web Developer's Virtual Library.
ScriptSearch Java
Hundreds of free Java code files to download.
jGuru: Your View of the Java Universe
Customizable portal with online training, FAQs, regular news updates, and tutorials.
|