public List getStudent(){
if (student == null){
student = new ArrayList();
}
……
[/Quote]
你这个应该不是用jaxb做的吧,下面是我的类结构:
objectFacotry:
//
// This file was generated by the JavaTM Architecture for XML Binding(JAXB) Reference Implementation, vhudson-jaxb-ri-2.1-661
// See <a href="http://java.sun.com/xml/jaxb">http://java.sun.com/xml/jaxb</a>
// Any modifications to this file will be lost upon recompilation of the source schema.
// Generated on: 2011.08.15 at 07:19:41 ���� CST
//
/**
* This object contains factory methods for each
* Java content interface and Java element interface
* generated in the com package.
* <p>An ObjectFactory allows you to programatically
* construct new instances of the Java representation
* for XML content. The Java representation of XML
* content can consist of schema derived interfaces
* and classes representing the binding of schema
* type definitions, element declarations and model
* groups. Factory methods for each of these are
* provided in this class.
*
*/
@XmlRegistry
public class ObjectFactory {
private final static QName _Root_QNAME = new QName("", "student");
/**
* Create a new ObjectFactory that can be used to create new instances of schema derived classes for package: generated
*
*/
public ObjectFactory() {
}
/**
* Create an instance of {@link Foo }
*
*/
public Student createFoo() {
return new Student();
}
/**
* Create an instance of {@link JAXBElement }{@code <}{@link Foo }{@code >}}
*/
@XmlElementDecl(namespace = "", name = "student")
public JAXBElement<Student> createRoot(Student value) {
return new JAXBElement<Student>(_Root_QNAME, Student.class, null, value);
}
}
package-info:
//
// This file was generated by the JavaTM Architecture for XML Binding(JAXB) Reference Implementation, vhudson-jaxb-ri-2.1-661
// See <a href="http://java.sun.com/xml/jaxb">http://java.sun.com/xml/jaxb</a>
// Any modifications to this file will be lost upon recompilation of the source schema.
// Generated on: 2011.08.15 at 07:19:41 ���� CST
//
student:
//
// This file was generated by the JavaTM Architecture for XML Binding(JAXB) Reference Implementation, vhudson-jaxb-ri-2.1-661
// See <a href="http://java.sun.com/xml/jaxb">http://java.sun.com/xml/jaxb</a>
// Any modifications to this file will be lost upon recompilation of the source schema.
// Generated on: 2011.08.15 at 07:19:41 ���� CST
//
/**
* Gets the value of the name property.
*
* @return
* possible object is
* {@link String }
*
*/
public String getName() {
return name;
}
/**
* Sets the value of the name property.
*
* @param value
* allowed object is
* {@link String }
*
*/
public void setName(String value) {
this.name = value;
}
/**
* Gets the value of the age property.
*
*/
public int getAge() {
return age;
}
/**
* Sets the value of the age property.
*
*/
public void setAge(int value) {
this.age = value;
}
/**
* Gets the value of the sex property.
*
* @return
* possible object is
* {@link String }
*
*/
public String getSex() {
return sex;
}
/**
* Sets the value of the sex property.
*
* @param value
* allowed object is
* {@link String }
*
*/
public void setSex(String value) {
this.sex = value;
}
/**
* Gets the value of the phone property.
*
* @return
* possible object is
* {@link String }
*
*/
public String getPhone() {
return phone;
}
/**
* Sets the value of the phone property.
*
* @param value
* allowed object is
* {@link String }
*
*/
public void setPhone(String value) {
this.phone = value;
}
public List getStudent(){
if (student == null){
student = new ArrayList();
}
return student;
}
}
XML生成的对象强制类型转换为students类型
Students students = (students)Object;
Iterator it = students.getStudent.iterator();
while(it.hasNext()){
Student student = (Student)it.next();//即可得到多个student对象。这里之前也要构建一个Student的包装类。
}