XML : JAXB basics and parsing xml

I have understood basics about JAXB. I tried one sample program and need some help.

  1. I created a sample JAXB project and tried parsing one xsd and its xml file.. got error. Later I figured out that I need jdk i my targeted run-times as JAXB uses some extra files that are not in JRE. Can some explain more please?

  2. then I have parsed the files.I haven't worked with xml's before so I am not sure what syntax is to be followed. I think my xml file should have some mentioning about xsd file. Is this correct? As I parsed in one of the classes I got this code generated:

    @XmlAccessorType(XmlAccessType.FIELD) @XmlType(name = "BookForm", propOrder = { "author", "title", "genre", "price", "pubDate", "review" })

shouldn't these have datatypes in front of them?

My sample xsd is:

  <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"          targetNamespace="urn:books"          xmlns:bks="urn:books">  <xsd:element name="books" type="bks:BooksForm"/>  <xsd:complexType name="BooksForm">  <xsd:sequence>    <xsd:element name="book"                 type="bks:BookForm"                 minOccurs="0"                 maxOccurs="unbounded"/>    </xsd:sequence>  </xsd:complexType>  <xsd:complexType name="BookForm">  <xsd:sequence>    <xsd:element name="author"   type="xsd:string"/>    <xsd:element name="title"    type="xsd:string"/>    <xsd:element name="genre"    type="xsd:string"/>    <xsd:element name="price"    type="xsd:float" />    <xsd:element name="pub_date" type="xsd:date" />    <xsd:element name="review"   type="xsd:string"/>  </xsd:sequence>  <xsd:attribute name="id"   type="xsd:string"/>  </xsd:complexType>    

My sample xml is:

  <?xml version="1.0"?>  <x:books xmlns:x="urn:books">  <book id="bk001">    <author>Writer</author>    <title>The First Book</title>    <genre>Fiction</genre>    <price>44.95</price>    <pub_date>2000-10-01</pub_date>    <review>An amazing story of nothing.</review>  </book></x:books>    

where can I get more info about all these annotations and how does JAXB generates classes?

No comments:

Post a Comment