Академический Документы
Профессиональный Документы
Культура Документы
XML Java
.
vtnk@yandex.ru
1.
""
2.
API
(, DOM, JDOM)
: XML-
:
,
, , ..
Java
DOM
XML-
()
JAXB. XML-
.
: ,
.
XML.
:
, "",
,
.
Java
XML-
JAXB
-
.
-
, ..
,
Java
XML-
XML-
Java
Java
: class Book
import java.io.*;
import java.util.logging.*;
import javax.xml.bind.*;
import javax.xml.bind.annotation.XmlRootElement;
class Author {
Author(){};
Author(String firstName, String lastName) {
this.firstName = firstName;
this.lastName = lastName;
}
private String firstName;
private String lastName;
public String getFirstName() {return firstName;}
public void setFirstName(String firstName)
{this.firstName = firstName;}
public String getLastName() {return lastName;}
public void setLastName(String lastName)
{this.lastName = lastName;}
}
@XmlRootElement
class Book {
private Author author;
private String title;
private int year;
Book(){};
Book(Author author, String title, int year) {
this.author = author;
this.title = title;
this.year = year;
}
public Author getAuthor() {return author;}
public void setAuthor(Author author) {this.author = author;}
public String getTitle() {return title;}
public void setTitle(String title){this.title = title;}
public int getYear() {return year;}
public void setYear(int year) {this.year = year;}
}
//
Author pushkin = new Author("", "");
Book poltava = new Book(pushkin, "", 2008);
//
File of = new File("book.xml");
os = new FileOutputStream(of);
//
JAXBContext context = JAXBContext.newInstance(Book.class);
Marshaller m = context.createMarshaller();
m.marshal(poltava, os);
os.close();
} catch (IOException ex) {
Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
} catch (JAXBException ex) {
Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
}
}
}
?
( book.xml)
2008
( GIF 22 )
. :
JAXB, 1 (
http://www.ibm.com/developerworks/ru/library/x-pracdb2/index.html
), 2 (
http://www.ibm.com/developerworks/ru/library/x-pracdb3/index.html)
Antonio Goncalves. Generate an XML Document from an Object
Model with JAXB 2 (
http://www.devx.com/Java/Article/34069/0/page/1)
Ed Ort and Bhakti Mehta. Java Architecture for XML Binding (JAXB)
(http://java.sun.com/developer/technicalArticles/WebServices/jaxb/)
. XML Java: XML
() (http://www.interface.ru/home.asp?artId=16134)