Professional Documents
Culture Documents
DATE : 05/07/2016
AIM
To implement XSL Transformation of the given XML document.
ALGORITHM
STEP 1: Start the program.
STEP 2: Design an xml document book.xml including elements title, author,
Publication, price. Etc.
STEP 3: Design an xsl style sheet and do the following.
(a).Open a template tag to find matching books.
(b).Open a table tag for creating a table that includes columns such
as title, author, publication, price.
(c). Retrieve the data from books xml document to view the records in
table format.
STEP 4: Stop the program.
PROGRAM CODE
bk.xsl
<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:fo="http://www.w3.org/1999/XSL/Format">
<xsl:template match="/">
<html>
<body bgcolor="pink">
<h1><center>BOOK DETAILS</center></h1>
<table border="2" color="blue">
<tr bgcolor="lightblue">
<th align="center">TITLE</th>
<th align="center">AUTHOR</th>
<th align="center">PRICE</th>
<th align="center">EDITION</th>
<th align="center">PUBLISHER</th>
<th align="center">EMAIL</th>
</tr>
<xsl:for-each select="bookdetail/book">
<tr bgcolor="lightblue">
<td align="center">
<xsl:value-of select="title"/>
</td>
<td align="center">
<xsl:value-of select="author"/>
</td>
<td align="center">
<xsl:value-of select="price"/>
</td>
<td align="center">
<xsl:value-of select="edition"/>
</td>
<td align="center">
<xsl:value-of select="publisher"/>
</td>
<td align="center">
<xsl:value-of select="email"/>
</td>
</tr>
</xsl:for-each>
</table>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
bk.xml
3
RESULT
The XSLT program has been executed successfully in web Browser.
EX NO. : 02
DATE : 12/07/2016
AIM
To import and Export XML file from and into SQL Server table.
ALGORITHM
STEP 1: Develop an XML file and save it in C:\Products.xml.
STEP 2: Create a table Products in SQL Server to store the XML data.
STEP 3: Run the query to read the XML file as BLOB data.
STEP 4: Display the result in the table format.
STEP 5: Design a table student with field name sid and sname.
STEP 6: Execute the query to parse the table datas and project as an XML
document.
STEP 7: Stop the program.
PROGRAM CODE
Products.xml
<Products>
<Product>
<SKU>1</SKU>
<Desc>Book</Desc>
</Product>
<Product>
<SKU>2</SKU>
<Desc>DVD</Desc>
</Product>
<Product>
<SKU>3</SKU>
<Desc>Video</Desc>
</Product>
</Products>
SQL CREATION
CREATE TABLE Products(sku INT PRIMARY KEY,product_desc VARCHAR(30));
INSERT INTO Products (sku, product_desc)
SELECT X.product.query('SKU').value('.', 'INT'),X.product.query('Desc').value('.',
'VARCHAR(30)')FROM ( SELECT CAST(x AS XML)
FROM OPENROWSET( BULK 'C:\Products.xml',SINGLE_BLOB) AS T(x) ) AS T(x)
CROSS APPLY x.nodes('Products/Product') AS X(product);
SELECT sku, product_desc
FROM Products;
OUTPUT
10
11
12
RESULT
Thus the import and export of XML document is done successfully.
13
14
EX NO. : 03
INTERNAL AND EXTERNAL DTD CREATION
DATE : 19/07/2016
AIM
To create a program for internal and external DTD using DOCTYPE element.
ALGORITHM
STEP 1: Start the program.
STEP 2: Create a DTD (Document type definition) file to define the data types
of XML elements.
STEP 3: Embed the dtd file in the DOCTYPE element.
STEP 4: Design an xml document with fields name, quantity, price and brand
of peripheral parent element.
STEP 5: Perform XSL Transformation to project the records in table format in
the browser.
STEP 6: Stop the program.
PROGRAM CODE
Rt.xml
15
Rt.xsl
<?xml version="1.0" encoding="ISO-8859-1"?>
16
17
</tr>
</xsl:for-each>
</table>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
OUTPUT
18
19
20
21
RESULT
Thus, XSL Transformation using internal and external DTD executed successfully.
22
EX NO. : 04
XML SCHEMA CREATION
DATE : 26/07/2016
AIM
To create an xml schema for the Ship order xml document.
ALGORITHM
STEP 1: Start the program.
STEP 2: Develop an xml document for Ship order with records ship
Name, address, city, country and link xml into the schema file.
STEP 3: Define an xml schema for the succeeding elements and its attributes.
(a) Name, address, city, country are elements.
(b) Ship branch as an attribute.
(c)Create and complex type for elements and attributes.
STEP 4: Save the file as shiporder.xsl
STEP 5: Pin shiporder.xsl into the xml document.
STEP 6: Execute the program & project the information.
STEP 7: Stop the program.
23
PROGRAM CODE
Shiporder.xml
<?xml version="1.0" encoding="UTF-8"?>
<shiporder shiporderid="889923" xmlns:xsi="http://www.w3.org/2001/XMLSchemaInstance" xsi:noNameSpaceSchemaLocation="shiporder.xsd">
<orderperson>Jaichandran</orderperson>
<shipto>
<name>Bala</name>
<address>M.K.B NAGAR</address>
<city>CHENNAI</city>
<country>INDIA</country>
</shipto>
<item>
<title>Empirebullesque</title>
<note>special Edition</note>
<quantity>1</quantity>
<price>10.90</price>
</item>
<item>
<title>hide Your Heart</title>
<quantity>1</quantity>
<price>9.90</price>
</item>
</shiporder>
24
Shiporder.xsl
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="shiporder">
<xs:complexType>
<xs:sequence>
<xs:element name="orderperson" type="xs:string"/>
<xs:element name="shipto">
<xs:complexType>
<xs:sequence>
<xs:element name="name" type="xs:string"/>
<xs:element name="address" type="xs:string"/>
<xs:element name="city" type="xs:string"/>
<xs:element name="country" type="xs:string"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="item" maxOccurs="unbounded">
<xs:complexType>
<xs:sequence>
<xs:element name="title" type="xs:string"/>
<xs:element name="note" type="xs:string" minOccurs="0"/>
<xs:element name="quantity" type="xs:positiveInteger"/>
<xs:element name="price" type="xs:decimal"/>
</xs:sequence>
</xs:complexType>
</xs:element>
25
</xs:sequence>
<xs:attribute name="orderid" type="xs:string" use="required"/>
</xs:complexType>
</xs:element>
</xs:schema>
26
OUTPUT
27
28
RESULT
Thus the XML Schema. Creation is done successfully.
29
EX NO. : 05(A)
PARSING XML DOCUMENT USING DOM PARSER
DATE : 02/08/2016
AIM
To read a XML Document using DOM Parser.
ALGORITHM
STEP 1: Start the program.
STEP 2: Design an xml document input.xml with fields
Firstname, lastname, nickname, and marks.
STEP 3: Create a test.java file in the notepad.
STEP 4: Import the DOM Parser APIs to parse the XML file as a sequence of
events.
STEP 5: Execute the program and display the XML elements.
STEP 6: Stop the program.
30
PROGRAM CODE
Input.xml
<?xml version="1.0"?>
<class>
<student rollno="1001">
<firstname>prassanna</firstname>
<lastname>kumar</lastname>
<nickname>prassy</nickname>
<marks>85</marks>
</student>
<student rollno="1002">
<firstname>bala</firstname>
<lastname>chandran</lastname>
<nickname>Balz</nickname>
<marks>90</marks>
</student>
</class>
31
Test.java
import java.io.File;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.DocumentBuilder;
import org.w3c.dom.Document;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import org.w3c.dom.Element;
public class test
{
public static void main(String[] args)
{
try
{
File inputFile=new File("input.xml");
DocumentBuilderFactory dbFactory=DocumentBuilderFactory.newInstance();
DocumentBuilder dBuilder=dbFactory.newDocumentBuilder();
Document doc= dBuilder.parse(inputFile);
doc.getDocumentElement().normalize();
System.out.println("Root Element:" +doc.getDocumentElement().getNodeName());
NodeList nList=doc.getElementsByTagName("student");
System.out.println("--------------------------------------------");
for(int temp=0;temp<nList.getLength();temp++)
{
Node nNode=nList.item(temp);
System.out.println("\nCurrent Element:"+nNode.getNodeType());
if(nNode.getNodeType()==Node.ELEMENT_NODE){
32
33
OUTPUT
34
35
RESULT
Thus the XML Document is parsed successfully using DOM Parser and verified
successfully.
36
37
EX NO. : 05(B)
PARSING XML DOCUMENT USING SAX PARSER
DATE : 09/08/2016
AIM
To Parse an XML document using SAX parser.
ALGORITHM
STEP 1: Start the program.
STEP 2: Design an xml document input.xml with fields
Firstname, lastname, nickname, and marks .
STEP 3: Create a UserHandler.java to print the XML elements.
STEP 4: Import the SAX Parser APIs to parse the XML Document.
STEP 5: Execute the program & Project the data.
STEP 6: Stop the program.
PROGRAM CODE
38
UserHandler.java
import org.xml.sax.Attributes;
import org.xml.sax.SAXException;
import org.xml.sax.helpers.DefaultHandler;
public class UserHandler extends DefaultHandler
{
boolean bFirstName=false;
boolean bLastName=false;
boolean bNickName=false;
boolean bMarks=false;
@Override
public void startElement(String uri,String localName,String qName,Attributes attributes)
throws SAXException{
if(qName.equalsIgnoreCase("student"))
{
String rollNo=attributes.getValue("rollno");
System.out.println("Roll No: " + rollNo);
}
else if(qName.equalsIgnoreCase("firstname"))
{
bFirstName=true;
}
else if(qName.equalsIgnoreCase("lastname"))
{
bLastName=true;
}
else if(qName.equalsIgnoreCase("nickname"))
39
{
bNickName=true;
}
else if(qName.equalsIgnoreCase("marks"))
{
bMarks=true;
}
}
@Override
public void endElement(String uri,String localName,String qName) throws
SAXException
{
if(qName.equalsIgnoreCase("student"))
{
System.out.println("End Element : " + qName);
}
}
@Override
public void characters(char ch[],int start,int length)
throws SAXException
{
if(bFirstName)
{
System.out.println("First Name: "+new String(ch,start,length));
bFirstName=false;
}
else if(bLastName)
40
{
System.out.println("Last Name :"+new String(ch,start,length));
bLastName=false;
}
else if(bNickName)
{
System.out.println("Nick Name : "+new String(ch,start,length));
bNickName=false;
}
else if(bMarks)
{
System.out.println("Marks : "+new String(ch,start,length));
bMarks=false;
}
}
}
SAXParserDemo.java
import java.io.File;
import javax.xml.parsers.SAXParser;
import javax.xml.parsers.SAXParserFactory;
import org.xml.sax.Attributes;
import org.xml.sax.SAXException;
import org.xml.sax.helpers.DefaultHandler;
public class SAXParserDemo{
public static void main(String[] args)
{
try
41
{
File inputFile=new File("input.xml");
SAXParserFactory factory=SAXParserFactory.newInstance();
SAXParser saxParser=factory.newSAXParser();
UserHandler userhandler=new UserHandler();
saxParser.parse(inputFile,userhandler);
}
catch(Exception e)
{
e.printStackTrace();
}
}
}
class UserHandler extends DefaultHandler
{
boolean bFirstName=false;
boolean bLastName=false;
boolean bNickName=false;
boolean bMarks=false;
@Override
public void startElement(String uri,String localName,String qName,Attributes attributes)
throws SAXException{
if(qName.equalsIgnoreCase("student"))
{
String rollNo=attributes.getValue("rollno");
System.out.println("Roll No: " + rollNo);
}
42
else if(qName.equalsIgnoreCase("firstname"))
{
bFirstName=true;
}
else if(qName.equalsIgnoreCase("lastname"))
{
bLastName=true;
}
else if(qName.equalsIgnoreCase("nickname"))
{
bNickName=true;
}
else if(qName.equalsIgnoreCase("marks"))
{
bMarks=true;
}
}
@Override
public void endElement(String uri,String localName,String qName)
throws SAXException
{
if(qName.equalsIgnoreCase("student"))
{
System.out.println("End Element : " + qName);
}
}
@Override
43
44
45
RESULT
Thus the XML document is parsed successfully using SAX Parser.
EX NO . : 06
DATE : 16/08/2016
46
AIM
To create a Web Service creation using JAX-WS Technology.
ALGORITHM
PROGRAM CODE
BookApprover.java
package bookservice;
47
import javax.jws.WebService;
import javax.jws.WebMethod;
import javax.xml.ws.Endpoint;
@WebService
public class BookApprover
{
@WebMethod
public boolean approve(String name)
{
if( name.equals("csharp") ||name.equals("cpp") || name.equals("java"))
return true;
else
return false;
}
public static void main(String args[])
{
BookApprover la = new BookApprover();
Endpoint endpoint =Endpoint.publish("http://localhost:8080/bookapprover",la);
}
}
BookClient.java
package client;
class BookClient {
48
OUTPUT
49
50
51
RESULT
Thus a web service and a client application is created successfully.
52
EX NO . : 07
DATE : 23/08/2016
AIM
To create a Web Service using JAX-RS.
ALGORITHM
53
54
55
56
57
58
59
60
PROGRAM CODE
GenericResource.java
package main;
import javax.jws.WebService;
import javax.jws.WebMethod;
import javax.jws.WebParam;
@WebService(serviceName = "NewWebService")
public class NewWebService {
/**
* This is a sample web service operation
*/
@WebMethod(operationName = "hello")
public String hello(@WebParam(name = "name") String txt) {
return "Hello " + txt + " !";
}
/**
* Web service operation
*/
@WebMethod(operationName = "add")
public int add(@WebParam(name = "a") int a, @WebParam(name = "b") int b) {
//TODO write your implementation code here:
return a+b;
}
}
61
OUTPUT
62
RESULT
Thus the web service is created successfully using JAX-RS.
63
64
EX NO. : 08(A)
DATE : 30/08/2016
AIM
To create a web service for calculator with appropriate client program.
ALGORITHM
STEP 1: Start the program.
STEP 2: Create a web service for calculator by selecting file
Website-> Asp.NetWebServices and click ok.
65
STEP 3: Define the operations add, sub, mul and div using C#.
66
67
69
70
71
72
PROGRAM CODE
Airthmatic.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Services;
namespace calculator1
{
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[System.ComponentModel.ToolboxItem(false)]
public class operation : System.Web.Services.WebService
{
[WebMethod]
public string calculate(string first, string second, char sign)
{
string result;
switch (sign)
{
case '+':
73
{
result = (Convert.ToInt32(first) + Convert.ToInt32(second)).ToString();
break;
}
case '-':
{
result = (Convert.ToInt32(first) - Convert.ToInt32(second)).ToString();
break;
}
case '*':
{
result = (Convert.ToInt32(first) * Convert.ToInt32(second)).ToString();
break;
}
case '/':
{
result = (Convert.ToInt32(first) / Convert.ToInt32(second)).ToString();
break;
}
default:
result = "Invalid";
break;
}
return result;
}
}
CLIENT PROGRAM
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace simple_calc
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
string i, j;
static char c;
private void button1_Click(object sender, EventArgs e)
{
textBox1.Text += Convert.ToString(1);
}
74
i = textBox1.Text;
textBox1.Text = "";
c = '/';
}
private void button14_Click(object sender, EventArgs e)
{
i = textBox1.Text;
textBox1.Text = "";
c = '*';
}
private void button15_Click(object sender, EventArgs e)
{
j = textBox1.Text;
function.operation obj = new function.operation();
textBox1.Text = obj.calculate(i,j,c);
}
private void button16_Click(object sender, EventArgs e)
{
textBox1.Text = "";
}
}
}
OUTPUT
76
77
78
RESULT
Thus the Calculator web service is executed successfully using ASP.NET.
79
EX NO. : 08(B)
WEB SERVICE FOR TEMPERATURE CONVERSION
DATE : 06/09/2016
AIM
To create a web service for Temperature Conversion with appropriate client
program.
ALGORITHM
STEP 1: Start the program.
STEP 2: Create a web service for temperature onto select file
Website-> Asp.NetWebServices and click ok.
80
STEP 3: Add the function code for the function Celsius and fareinheat to the
service.C# file.
81
84
PROGRAM CODE
Tempature.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Services;
namespace Tempature
{
/// <summary>
/// Summary description for Tempature
/// </summary>
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[System.ComponentModel.ToolboxItem(false)]
// To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment
the following line.
// [System.Web.Script.Services.ScriptService]
public class Tempature : System.Web.Services.WebService
{
[WebMethod]
public int far(int c)
{
return c*9/25+32;
}
[WebMethod]
public int cal(int f)
{
return f * 9 / 25 + 32;
}
}}
86
CLIENT PROGRAM
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace Temp
{
public partial class Form1 : Form
{
Temp.Tempature obj = new Temp.Tempature();
int a, b, c, f;
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
a = Convert.ToInt32(textBox1.Text);
//b = Convert.ToInt32(textBox2.Text);
c = obj.far(a);
textBox2.Text = c.ToString();
}
private void button2_Click(object sender, EventArgs e)
{
//a = Convert.ToInt32(textBox1.Text);
b = Convert.ToInt32(textBox2.Text);
f = obj.cal( b);
textBox1.Text = f.ToString();
}}}
87
OUTPUT
88
RESULT
Thus the Web Service for temperature conversion is created and executed
successfully using ASP.NET.
89
EX NO. : 08(C)
WEB SERVICE FOR CURRENCY CONVERSION
DATE : 20/09/2016
AIM
To create a web service for Currency conversion with appropriate client programs.
ALGORITHM
STEP 1: Start the program.
STEP 2: Create a web service for temperature onto select file
Website-> Asp.NetWebServices and click ok.
90
STEP 3: Add the function code for the function euro,usd,pound Currency
Conversion to the service.C# file.
91
92
93
94
95
PROGRAM CODE
Webform1.aspx
Imports System.Web
Imports System.Web.Services
Imports System.Web.Services.Protocols
<WebService(Namespace:="http://tempuri.org/")> _
<WebServiceBinding(ConformsTo:=WsiProfiles.BasicProfile1_1)> _
<Global.Microsoft.VisualBasic.CompilerServices.DesignerGenerated()> _
Public Class Service
Inherits System.Web.Services.WebService
<WebMethod()> _
Public Function usd(ByVal i As Integer) As String
Return (i / 40)
96
End Function
<WebMethod()> _
Public Function euro(ByVal i As Integer) As String
Return (i / 50)
End Function
<WebMethod()> _
Public Function pound(ByVal i As Integer) As String
Return (i / 60)
End Function
<WebMethod()> _
Public Function dollar(ByVal i As Integer) As String
Return (i / 70)
End Function
End Class
WebForm.aspx.cs
Public Class Form1
Dim obj As New localhost.Service()
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
TextBox2.Text = obj.usd(TextBox1.Text)
TextBox3.Text = obj.euro(TextBox1.Text)
TextBox4.Text = obj.pound(TextBox1.Text)
TextBox5.Text = obj.dollar(TextBox1.Text)
End Sub
End Class
97
OUTPUT
98
99
100
RESULT
Thus the Web Service for currency conversion is created and executed
successfully using ASP.NET.
101
EX NO . : 09
DATE : 27/09/2016
AIM
To create Web Service creation using NET BEANS.
ALGORITHM
STEP 1: Start the program.
STEP 2: Select File-> New project -> web service specify the name.
102
103
104
105
STEP 4: Write the coding in the add.java clean and build the project.
106
107
108
PROGRAM CODE
Add.java
package main;
import javax.jws.WebService;
import javax.jws.WebMethod;
import javax.jws.WebParam;
@WebService(serviceName = "NewWebService")
public class NewWebService {
@WebMethod(operationName = "hello")
public String hello(@WebParam(name = "name") String txt) {
return "Hello " + txt + " !";
}
/**
* Web service operation
*/
@WebMethod(operationName = "add")
public int add(@WebParam(name = "a") int a, @WebParam(name = "b") int b) {
//TODO write your implementation code here:
return a+b;
}
}
109
OUTPUT
110
RESULT
Thus the web service is created successfully using Net Beans.
111
112
EX NO. : 10
JAXB- MARSHALING AND UNMARSHALLING
DATE : 04/10/2016
AIM
To perform JAXB Marshaling and UnMarshalling by converting a Java Object to
XML file and vice versa.
ALGORITHM
STEP 1: Start the program.
STEP 2: Create an Employee class with attributes id,gender,name,role,password.
STEP 3: Define a method jaxbObjectToXML() to marshal the employee object
to XML file Jaxb-emp.xml
STEP 4: Declare a method jaxbXMLtoObject() to unmarshal the XML file to
employee object .
STEP 5: Execute the program & Project the employee object.
STEP 6: Stop the program.
PROGRAM CODE
113
Employee.java
import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlTransient;
import javax.xml.bind.annotation.XmlType;
@XmlRootElement(name = "Emp")
@XmlType(propOrder = {"name", "age", "role", "gender"})
public class Employee {
private int id;
private String gender;
private int age;
private String name;
private String role;
private String password;
@XmlTransient
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
@XmlAttribute
public int getId() {
return id;
}
public void setId(int id) {
114
this.id = id;
}
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
@XmlElement(name = "gen")
public String getGender() {
return gender;
}
public void setGender(String gender) {
this.gender = gender;
}
public String getRole() {
return role;
}
public void setRole(String role) {
this.role = role;
}
115
@Override
public String toString() {
return "ID = " + id + " NAME=" + name + " AGE=" + age + " GENDER=" +
gender + " ROLE=" role + " PASSWORD=" + password;
}
}
JAXBExample.java
import java.io.File;
import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBException;
import javax.xml.bind.Marshaller;
import javax.xml.bind.Unmarshaller;
public class JAXBExample {
private static final String FILE_NAME = "jaxb-emp.xml";
public static void main(String[] args) {
Employee emp = new Employee();
emp.setId(1);
emp.setAge(25);
emp.setName("Anitha");
emp.setGender("Female");
emp.setRole("Developer");
emp.setPassword("sensitive");
jaxbObjectToXML(emp);
Employee empFromFile = jaxbXMLToObject();
System.out.println(empFromFile.toString());
}
private static Employee jaxbXMLToObject() {
116
try {
JAXBContext context = JAXBContext.newInstance(Employee.class);
Unmarshaller un = context.createUnmarshaller();
Employee emp = (Employee) un.unmarshal(new File(FILE_NAME));
return emp;
} catch (JAXBException e) {
e.printStackTrace();
}
return null;
}
private static void jaxbObjectToXML(Employee emp)
try {
JAXBContext context = JAXBContext.newInstance(Employee.class);
Marshaller m = context.createMarshaller();
//for pretty-print XML in JAXB
m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE);
// Write to System.out for debugging
// m.marshal(emp, System.out);
// Write to File
m.marshal(emp, new File(FILE_NAME));
} catch (JAXBException e) {
e.printStackTrace();
}
}
}
Jaxb-emp.xml
117
OUTPUT
118
119
RESULT
Thus JAXB marshaling and unmarshaling is done successfully.
120