package techtip;
import javax.xml.bind.annotation.*;
import java.util.Collection;
import techtip.Person;
@XmlRootElement
public class Scientist {
private Person person;
private String researchInstitute;
private Collection publications;
public Scientist() {
}
public Scientist (Person p, String ri, Collection col) {
person = p;
researchInstitute = ri;
publications = col;
}
public Person getPerson() {
return person;
}
public void setPerson (Person value) {
person = value;
}
public String getresearchInstitute() {
return researchInstitute;
}
public void setResearchInstitute(String institute) {
researchInstitute = institute;
}
public Collection getPublications() {
return publications;
}
public void setPublications(Collection publish) {
publications = publish;
}
} |
package techtip;
import javax.xml.bind.annotation.*;
import techtip.*;
@XmlType
public class Person {
private String name;
private int age;
private String sex;
public Person() {
}
public Person(String name, int age, String sex){
this.name=name;
this.age = age;
this.sex = sex;
}
public String getName() {
return name;
}
public void setName(String value) {
name = value;
}
public int getAge() {
return age;
}
public void setAge(int value) {
age = value;
}
public String getSex() {
return sex;
}
public void setSex(String value) {
sex = value;
}
} |
C:jaxbtechtipclasses>set path=%path%;C:jwsdp-2.0jaxbbin;
C:jaxbtechtipclasses>schemagen
Usage: schemagen [-options ...] <java files>
Options:
-d <path> : specify where to place processor and javac generated class files
-cp <path> : specify where to find user specified files
-classpath <path> : specify where to find user specified files
-version : display version information
C:jaxbtechtipclasses>schemagen techtip.Scientist
Note: Writing schema1.xsd |
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<xs:schema version="1.0" xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="scientist" type="scientist"/>
<xs:complexType name="scientist">
<xs:sequence>
<xs:element name="person" type="person" minOccurs="0"/>
<xs:element name="publications" type="xs:anyType" nillable="true" maxOccurs="unbounded" minOccurs="0"/>
</xs:sequence>
</xs:complexType>
<xs:complexType name="person">
<xs:sequence>
<xs:element name="age" type="xs:int"/>
<xs:element name="name" type="xs:string" minOccurs="0"/>
<xs:element name="sex" type="xs:string" minOccurs="0"/>
</xs:sequence>
</xs:complexType>
</xs:schema> |