How to map xml attribute values to java class attributes using jaxB or any other better method?



this is my test.xml and i want to tag attribute name values i.e bookid, bookname and noOfPages to attributes of Book.java class



<?xml version="1.0" encoding="UTF-8"?>
<tns:class xmlns:tns="http://ift.tt/1wa7VrH" xmlns:xsi="http://ift.tt/ra1lAU" xsi:schemaLocation="http://ift.tt/1wa7VrH test.xsd ">
<attr name="bookid" primary="true"/>
<attr name="bookname" primary="false"/>
<attr name="noOfPages" primary="false"/>
<attr name="auth_name" primary="false"/>
</tns:class>




Book.java


package com.srl.rotelearning.test;


public class Book {



private int bookId;
private String bookname;
private int noOfPages;

public int getBookId() {
return bookId;
}

public int getNoOfPages() {
return noOfPages;
}

public void setNoOfPages(int noOfPages) {
this.noOfPages = noOfPages;
}

public void setBookId(int bookId) {
this.bookId = bookId;
}

public String getBookname() {
return bookname;
}

public void setBookname(String bookname) {
this.bookname = bookname;
}


} i tried using JAXB but i think we can map attribute names to class attributes. how do i map xml attribute values to my class attributes? plz give ans in detail as m new to using xml thanks :)


Tiada ulasan:

Catat Ulasan