WLSKB009 - Working With XML Using XMLBean Tutorial

Popular Courses

Browse Our Free Resources

  • whitepapers
  • whitepapers
  • webinars
  • blogs

Our Locations

Training Centres

Vancouver, BC
Calgary, AB
Edmonton, AB
Toronto, ON
Ottawa, ON
Montreal, QC
Hunt Valley

locations map


550 6th Av SW
Suite 475
Calgary, AB
T2P 0S2


821A Bloor Street West
Toronto, ON
M6G 1M1


409 Granville St
Suite 902
Vancouver, BC
V6C 1T2

U.S. Office

436 York Road
Suite 1
Jenkintown, PA

Other Locations

Dallas, TX
Miami, FL

Web Age Solutions Inc.


XMLBean is an alternative to the SAX and DOM API for parsing XML files. The technology is now publicly available from Apache under the XMLBeans project. Using XMLBean, you can read an update an XML document. Unlike the SAX or DOM API, XMLBean provides a strongly typed and object oriented approach. For example, the <customer> XML element is represented by the Customer class.

The structure of the XML document needs to be formally sepcified in a XML schema document (XSD). Once the XSD file is created, Workshop can generate the necessary Java classes to represent various elements in the schema.

Develop the Schema

Launch WebLogic Workshop. Create an application called BasicApp, unless it is already created from a previous tutorial. From the menubar, select File->New->Project.

Choose Schema and then Schema Project. Enter MySchemaProject as the project name. Click on Create.

Right click on MySchemaProject and select New->XML Schema. Enter library.xsd as the file name. Click on Create.

We will customize the name space to We will also register a new name space prefix called lib. Make the following changes shown in bold face.


Within the <schema> tag, enter the following schema.

<xs:complexType name="author">
  <xs:element name="name" type="xs:string"/>
<xs:complexType name="book">
  <xs:element name="title" type="xs:string"/>
  <xs:element name="isbn" type="xs:string"/>
  <xs:element name="author" type="lib:author" minOccurs="1" maxOccurs="unbounded"/>
<!-- A library is a sequence of book elements -->
<xs:element name="library">
   <xs:element name="book" type="lib:book" minOccurs="0" maxOccurs="unbounded"/>

Save changes. System will start to build the project and generate the XMLBean Java classes.

Classes are generated in the XML Bean Classes folder as shown above.

Use the XMLBean Classes

Within the BasicAppWeb project, create an XML file called library.xml with the following content.

<?xml version="1.0"?> 
     <lib:library xmlns:lib="">

<lib:book> <lib:title>2001 Space Oddyssey</lib:title> <lib:isbn>0451457994</lib:isbn> <lib:author> <lib:name>Arthur C. Clarke</lib:name> </lib:author> </lib:book>
  <lib:title>BEA WebLogic Workshop 8.1 Kick Start</lib:title>
   <lib:name>Albert J. Saganich</lib:name>
   <lib:name>Tom Hardy</lib:name>

Save and close the file.

Create a new Page Flow called BrowseBookFlow. Open the source code of the flow class. Add the following import statement.

import com.mycom.schemas.library.*;
import com.mycom.schemas.library.LibraryDocument.Library;  

Change the implementation of the begin() method to as follows.

protected Forward begin() throws Exception
    LibraryDocument doc = LibraryDocument.Factory.parse(
    Library lib = doc.getLibrary();
    Book books[] = lib.getBookArray();
    getRequest().setAttribute("books", books);
    return new Forward("success");

Save changes.

Open index.jsp. Set the contents of the <body> tag to as follows.

 <h2>Book List</h2>
  <netui-data:repeater dataSource="{request.books}">
    <netui:label value="{container.item.title} - ISBN: {container.item.isbn}"/><br/>

Save changes.


Start the server. Open a browser and enter the URL: http://localhost:7001/BasicAppWeb/BrowseBookFlow/BrowseBookFlowController.jpf



Email Address: *

Very useful Somewhat useful Not bad Needs many corrections


( * ) = mandatory field