利用 JavaBean 读取xml文件 (二)

2014-11-24 10:53:17 · 作者: · 浏览: 1
());
System.out.println(a.getDate());
System.out.println(a.getEmail());
System.out.println(a.getTitle());
System.out.println(a.getAuthors().getAddress()+" "+a.getAuthors().getAge()+" "+a.getAuthors().getSex());
System.out.println(a.getAuthors());
}
} catch (JAXBException e) {
e.printStackTrace();
}
}
}



[java]
package demo20130531; import javax.xml.bind.annotation.XmlRootElement; @XmlRootElement public class Article { private String title; private String author; private String email; private String date; private Authors authors; public String getTitle() { return title; } public void setTitle(String title) { this.title = title; } public String getAuthor() { return author; } public void setAuthor(String author) { this.author = author; } public String getEmail() { return email; } public void setEmail(String email) { this.email = email; } public String getDate() { return date; } public void setDate(String date) { this.date = date; } public Authors getAuthors() { return authors; } public void setAuthors(Authors authors) { this.authors = authors; } } package demo20130531;

import javax.xml.bind.annotation.XmlRootElement;
@XmlRootElement
public class Article {

private String title;

private String author;

private String email;

private String date;

private Authors authors;

public String getTitle() {
return title;
}

public void setTitle(String title) {
this.title = title;
}

public String getAuthor() {
return author;
}

public void setAuthor(String author) {
this.author = author;
}

public String getEmail() {
return email;
}

public void setEmail(String email) {
this.email = email;
}

public String getDate() {
return date;
}

public void setDate(String date) {
this.date = date;
}

public Authors getAuthors() {
return authors;
}

public void setAuthors(Authors authors) {
this.authors = authors;
}


}

< xml version="1.0" encoding="UTF-8" >

helloctlctl_cn@163.com1991-06-2922M
河南

[java]
package demo20130531; public class Authors { private int age; private String sex;//不可以是char类型 private String address; public int getAge() { return age; } public void setAge(int age) { this.age = age; } public String getSex() { return sex; } public void setSex(String sex) { this.sex = sex; } public String getAddress() { return address; } public void setAddress(String address) { this.address = address; } public String toString() { return "age:" + age + " sex:" + sex + " address:" + address; } } package demo20130531;

public class Authors {
private int age;
private String sex;//不可以是char类型
private String address;
public int getAge() {
return age;
}

public void setAge(int age) {
this.age = age;
}

public String getSex() {
return sex;
}

public void setSex(String sex) {
this.sex = sex;
}

public String getAddress() {
return addr