Skip to main content link. Accesskey S
  • Anonymous
  • Log on
  • Help
  • IBM logo
  • IBM Web Experience Factory wiki
  • All Wikis
  • Home
  • Community Articles
  • Product Documentation
  • Learning Center


Search

Advanced Search

Categories

Tag Cloud

  • 6.1
  • 6.1.2
  • 6.1.5
  • 6.1.5.1
  • 7.0
  • Ajax
  • Alerts
  • Annotations
  • attachment
  • best practices
  • BlackBerry
  • builder
  • builder faq
  • builders
  • charts
  • Code samples
  • Connections
  • css
  • Custom builder
  • CustomBuilder
  • dashboard
  • Data Access
  • data access faq
  • Data and variables
  • Database
  • Databases
  • Debugging
  • demo
  • demo models
  • demo projects
  • demo widget
  • demos
  • deployment
  • deployment faq
  • Deployment scenarios
  • development
  • dojo
  • Domino
  • faq
  • fixpack
  • General FAQ
  • getting started
  • Help
  • HTML
  • html templates
  • ILOG
  • integration
  • iPhone
  • JViews
  • Learning
  • Logging
  • lotus connections
  • Lotus Widget Factory
  • media dashboard
  • media pf
  • media widget
  • mobile
  • mobile smartphone development
  • Model development
  • new
  • Notifications
  • overview
  • page automation
  • Portal
  • Portal Integration
  • portal integration faq
  • Portlet
  • Portlet Factory 7
  • presentation
  • presentation faq
  • Profiling
  • Quickr
  • REST
  • rest faq
  • REST Service Call
  • restructure handler
  • rich ui
  • sample
  • sample application
  • samples
  • schema
  • Security
  • Smartphones
  • SOA
  • social
  • Source Control
  • sql
  • summary and drilldown
  • Team development
  • Troubleshooting
  • ui
  • User Interface
  • video
  • web 2.0
  • Web Experience Factory
  • Web Experience Factory 8
  • Web Services
  • websphere dashboard framework
  • wef
  • wpf
InformationInformation
You are currently viewing machine translated content. IBM translation might be available. Click IBM Translated Product Documentation to see what is available.X


Home > Samples and Techniques for Web Experience Factory > IBM - Using Portlet Factory's IXml and XmlUtil Interfaces
Rate this article 1 starRate this article 2 starsRate this article 3 starsRate this article 4 starsRate this article 5 stars

IBM - Using Portlet Factory's IXml and XmlUtil Interfaces 

expanded Abstract
collapsed Abstract
No abstract provided.

IXml and XMLUtil



Portlet Factory's IXml and XmlUtil interfaces are lightweight and powerful API's for working with XML data. An integral component of Portlet Factory internals, they are useful for creating, parsing, and setting various XML data.

This article and sample application demonstrates how you can use these API's to manipulate XML data in your application. The application will parse an ATOM feed and create a new XML structure.

The new XML is used to populate a Select input on a page, as shown in the following image.



 Screenshot of the Select Input

The sample application contains one model, IXmlSample.model.


IXmlSample.model
The atomFeed variable holds the ATOM feed XML to be parsed. The ATOM feed is based on a Lotus Quickr REST service that returns a feed of document libraries:


<?xml version="1.0" encoding="utf-8"?>

<service xmlns="http://purl.org/atom/app#" xmlns:atom="http://www.w3.org/2005/Atom">

<workspace>

<atom:title type="text">Teamspace Documents</atom:title>

<collection href="http://serv/dm/atom/library/111/feed" xmlns="xxx">

<atom:title type="text" xmlns:atom="http://serv/2005/Atom">HR Docs</atom:title>

<accept>application/*,image/*,*/*</accept>

</collection>

<collection href="http://serv/dm/atom/library/222/feed" xmlns="xxx">

<atom:title type="text" xmlns:atom="http://serv/2005/Atom">Sam's Library</atom:title>

<accept>application/*,image/*,*/*</accept>

</collection>

...

</workspace>

</service> 



The Select builder adds a Select input on the page. A Select builder can easily get its data from IXml variable in the following general form:


<RowSet>

<Row>

<label></label>

<value></label>

</Row>

<RowSet> 



Following this general form, the model contains a Variable builder, libraries, that is used for the Select builder's "Select Data" input. The variable's Type input is set to XML. Populated at runtime, libraries will contain data similar to this:



<Libraries>

 <Library>

   <label>My Library</label>

   <value>http://server/dm/atom/library/123/feed</value>

 </Library>

...

</Libraries> 



When the Action List main is called, the libraries variable is set to the return value of getLibraries method. And here is where the fun begins!
The getLibraries method uses IXml to parse the ATOM feed and create a new Xml variable suitable for the Select list.

Several XmlUtil and IXml methods are called:

    • XmlUtil.create() is used to create the elements in our new XML structure
    • IXml.findElement() is used to navigate, or skip down, to a particular place in the ATOM feed
    • IXml.getChildren() is used to get a List of child IXml elements.
    • IXml.getAttribute() is used to read in the value of an XML attribute
    • IXml.findElement() is used to find a subelement of an XML structure
    • IXml.getText() is used to retrieve the text value of an element < /li>
    • IXml.addChildWithText() is us ed to create Xml elements with text values.

// Create new <Libaries> XML structure IXml libs = XmlUtil.create("Libraries");



// Get var that holds the ATOM feed

IXml atomFeed = webAppAccess.getVariables().getXml("atomFeed");



// Skip down to the <collections> elements

IXml collectionsXml = atomFeed.findElement("service/workspace");



// For each lib, parse the title & feed url. Create a <Library> structure

// that contains the title and value. Add the <Library> structure to

// the <Libaries> structure

Iterator collections = collectionsXml.getChildren().iterator();

while(collections.hasNext())

{

IXml collection = (IXml) collections.next();

String colFeedUrl = collection.getAttribute("href");

String colTitle = collection.findElement("atom:title").getText();



IXml lib = XmlUtil.create("Library");

lib.addChildWithText("label", colTitle);

lib.addChildWithText("value", colFeedUrl);



libs.addChildElement(lib);

}

return libs; 



Installing the Sample
    • Create a new WebSphere Portlet Factory project.
    • Import the following zip as a WebSphere Portlet Factory archive IXmlSample.zip
    • The zip contains one model: models\samples\IXmlSample.model.

Reference


For more information, see the IXml and XmlUtil javadoc that ships with Portlet Factory. This is accessible by select Start> All Programs> IBM WebSphere> Portlet Factory> Documentation> Java API Documentation.


expanded Article information
collapsed Article information
Category:
Samples and Techniques for Web Experience Factory, Web Experience Factory, Samples and Techniques,
Tags:
Code samples, Data and variables

This Version: Version 20 August 3, 2010 10:59:21 AM by Keshi Dai  

expanded Attachments (2)
collapsed Attachments (2)

 


File TypeSizeFile NameCreated On
application/x-zip 2 KB IXmlSample.zip 5/5/08 10:54 AM
image/gif 5 KB pic1.gif 5/5/08 10:54 AM
expanded Versions (20)
collapsed Versions (20)
Version Comparison     
Version Date Changed by               Summary of changes
This version (20) Aug 3, 2010 10:59:21 AM Keshi Dai  
19 Jan 15, 2010 7:54:35 PM Rob Flynn  
18 Dec 31, 2009 8:42:15 AM Rob Flynn  
17 Dec 31, 2009 8:40:40 AM Rob Flynn  
16 Dec 8, 2008 2:01:16 PM Rob Flynn  
15 Oct 27, 2008 4:33:53 PM DeAnna Steiner  
14 Jul 8, 2008 4:21:02 PM S Alexander  
13 Jun 23, 2008 10:34:09 AM Rob Flynn  
12 Jun 19, 2008 12:24:30 PM Rob Flynn  
11 Jun 19, 2008 12:24:19 PM Rob Flynn  
10 Jun 17, 2008 1:30:16 PM R Flynn  
9 Jun 17, 2008 1:27:01 PM R Flynn  
8 Jun 17, 2008 1:21:20 PM R Flynn  
7 Jun 17, 2008 1:19:57 PM R Flynn  
6 Jun 13, 2008 3:57:26 PM Rob Flynn  
5 Jun 13, 2008 12:41:25 PM Rob Flynn  
4 Jun 13, 2008 9:54:30 AM Rob Flynn  
3 Jun 2, 2008 2:02:29 PM Rob Flynn  
2 May 27, 2008 9:11:49 AM Rob Flynn  
1 May 22, 2008 9:44:14 AM Rob Flynn  
expanded Comments (0)
collapsed Comments (0)
Copy and paste this wiki markup to link to this article from another article in this wiki.
Go ElsewhereStay ConnectedSubscribe to RSSHelpAbout
  • All Lotus and WebSphere Portal wikis
  • IBM developerWorks
  • IBM Software support
  • IBM Social Business User Experience Blog
  • IBMSocialBizUX on Twitter
  • IBMSocialBizUX on Facebook
  • Lotus product forums
  • IBM Social Business UX blog
  • IBM Collaboration Solutions
  • Recently added feedRecently added
  • Recently edited feedRecently edited
  • Recently added comments feedRecently Added Comments
  • Wiki Help
  • Forgot user name/password
  • Wiki design feedback
  • Content feedback
  • About the wiki
  • About IBM
  • Privacy
  • Contact IBM
  • IBM Terms of use
  • Wiki terms of use