Monday, April 18, 2011

XML Feature Pack Tech Preview Available

Just in time for IBM Impact, the IBM XML team cranked out an updated tech preview of the XML Feature Pack with three key new features.

First - XQuery modules is a way to break up larger XQuery based programs into modular units. This was the last optional feature of XQuery not yet supported and rounds out the XQuery 1.0 support. Not only does this feature help you break up your own XQuery programs, but it also allows you to use open source XQuery libraries such as FunctX.

Next is support for easier to bind Java functions. In previous releases you could binding to existing Java logic and data, but now binding to existing Java logic is even easier. The support is common across both XSLT 2.0 and XQuery and supports invocation of both instance and static methods. Here is an example that I showed at Impact:


package org.company;

public class Calculator {
public static int sqrt(int val) {
return (int)Math.sqrt(val);
}
}



<xsl:stylesheet version="2.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xltxe="http://www.ibm.com/xmlns/prod/xltxe-j"
xmlns:calc="http://com.example/myApp/calculator">

<xltxe:java-extension prefix="calc“ class="org.company.Calculator"/>

<xsl:template match="/">
<xsl:value-of select=“calc:sqrt(64) "/>
</xsl:template>

</xsl:stylesheet>


You can see in the XSLT that using our extention, we were able to map any functions starting with calc to Java calls to org.company.Calculator. Specifically the function sqrt was called in this example. With this support, no Java code is needed to link existing Java logic to an XSLT or XQuery program.

Finally, we spent alot of time on runtime error messages. We have made sure that error messages now include line and column numbers that help you track back to the error that caused execution to fail.

You can read more about these features on developerWorks and download the tech preview from the IBM download site.

Announcing the IBM WebSphere Application Server Migration Toolkit V3.0 Beta

The IBM WebSphere Application Server development team is pleased to announce the availability of the IBM WebSphere Application Server Migration Toolkit V3.0 Beta.

The V3.0 Beta builds upon the capabilities delivered in the V2.1 release, expanding support for migrating your Java Enterprise Edition applications to WebSphere Application Server. 
The V3.0 Beta continues to enhance the developer's migration experience with new support for migration to WebSphere Application Server V8.0 Beta. Simple remediation tools utilize Rational® source code scanning technology to identify and resolve known application migration issues. This enables developers to quickly identify changes required to migrate from previous product versions or from competitor's Application Server platforms. 

More details on the new features and beta program can be found on the IBM WebSphere Application Server V8.0 Beta home page. Just look under Integrated tooling. 
You can directly Download IBM® WebSphere® Application Server Migration Toolkit v3.0 Beta. 

We're excited to continue learning about your experiences with the Beta in the WebSphere Application Server 8 beta forum. 


Tuesday, April 5, 2011

WebSphere Application Server V8 Announced

Planned availability date
Bottom rule

  • June 17, 2011 - electronic delivery
  • July 22, 2011 - media packs

The formal announcement letter is available here.

V8 contains, as you may recall from previous blog posts, integrated versions of SCA, OSGi, XML, and CEA feature packs.

Please continue to enjoy the beta in the meantime!

--> updated link to remove mid-page jump. :-)

Saturday, March 19, 2011

WebSphere Application Server v8.0 Beta, March refresh

IBM have released a WAS v8.0 Beta refresh which includes some great new OSGi Applications functionality, including: In-place application update, a feature that allows administrators to manage and migrate their OSGi bundles at runtime, without application restart. Application extensions allow administrators to extend their applications at runtime with a Composite Bundle Archive (CBA), again with no application restart. There are also performance monitoring, security, session management, servlet 3.0 support for OSGi applications/components.

For more information on OSGi in the Beta, why not check out this short video on the Enterprise OSGi YouTube channel.  http://www.youtube.com/user/EnterpriseOSGi#p/a/u/0/3vRmzqHiJBY

To download the WAS v8.0 Beta and get playing with all the new features, visit the download site here ->
https://www14.software.ibm.com/iwm/web/cc/earlyprograms/websphere/wsasoa/download.shtml

Tuesday, March 8, 2011

Introducing the new Enterprise OSGi YouTube channel.

Over the last couple of weeks, I've been putting together a list of OSGi related talks that act as a useful resource for OSGi beginners.  I'm lucky enough to work in a development team full of talented people who are very happy to share their knowledge and experiences to customers and at conferences.  I wanted this youtube channel to provide a web resource so that we can share this information to a wider audience.

The short overview presentations are designed to giev the viewer a high level understanding of concepts without going into too much depth.  I'll put up links and follow up material which goes into more depth at our main OSGi home at

The new channel can be found at http://www.youtube.com/user/EnterpriseOSGi

Videos available right now on our new Enterprise OSGi channel include:

Big EARs and OSGi - Part 1, by Ian Robinson, IBM, Distinguished Engineer
Big EARs and OSGi - Part 2, by Ian Robinson, IBM, Distinguished Engineer
An Interview with Zoe Slattery, by Zoe Slattery, IBM, OSGi Technical Evangelist
JPA in OSGi, by Tim Ward, IBM, OSGi Applications developer in WAS.

More will be uploaded soon, so why not subscribe to the channel to get notification of when new videos are uploaded.  To subscribe, you'll need a YouTube account.  Click on the subscribe button on the top left of the Enterprise OSGi channel, shown below.


Friday, February 25, 2011

Great set of articles on Native Memory

I am currently helping a customer with a native memory issue causing OutOfMemory (OOM) exceptions. Most folks are familiar with Java heap memory issues (eg. too much caching eating up live memory or leaking objects), but native memory is also important especially when your application isn't so "pure" (spawning threads, lots of JNI, etc). How do you know if you have a native out of memory? You'll see that you'll get out of memory conditions when the Java heap still has plenty of room left over. In the case I'm working on now, we actually saw the out of memory well before the memory in the heap grew to the maximum size (-Xmx) of the heap. In trying to help the customer out, I found the following articles excellent. The first is a very good overview of native memory and how to diagnose. The second is our app server tech note on things to try in the case you believe you have a native memory issue.

Thanks for the memory - Understanding how the JVM uses native memory on Windows and Linux (Windows/Linux version, AIX version).

Troubleshooting native memory issues

Tuesday, February 8, 2011

ONLINE SAMPLES

The Samples section of the WAS V8 BETA Information Center is now live!!  http://publib.boulder.ibm.com/infocenter/wasinfo/beta/index.jsp

WebSphere Application Server V8 Beta samples are new and improved and now available for early testing to our WAS V8 Beta customers! Although clients will continue to find key samples installed with the product, additional samples are available online and can be accessed from a new section in the WAS V8 Beta Information Center. Now, samples, documentation, and other resources reside online, under one roof. This will increase availability and collaboration while providing samples in a time-sensitive manner.

Increasing Availability. The sample applications are now on the web, and users can browse individual samples with a direct link or find them using search engines. This is a first for WebSphere Application Server!


Adding Collaboration. As part of the new collaborative information center, users can comment on and rate samples, receive quick feedback, and sign up for updates.

Providing relevant samples in a time-sensitive manner. Online delivery allows samples to be added or updated periodically with regular updates to the information center.

The samples currently available in the Samples section of the WAS V8 Beta Information Center demonstrate the following technologies: Service Component Architecture (SCA), Communications Enabled Applications (CEA), OSGi applications, XML, and Internationalization service.

Look for more to come!

Monday, January 3, 2011

Help keep posts to this blog active in 2011

Unfortunately, none of my New Year's resolutions included blogging more often. I notice that the posts on this blog have fallen to approximately once a month. That likely isn't enough to keep all our great readers interested in repeating their visits (and Google analytics confirms this for me). The idea of this blog is to get experts across the WebSphere development labs blogging about topics across the application infrastructure set of products. I'm certain I will be blogging about XML, SOA, and performance topics this year. I'm also sure you'll hear more and more about WebSphere Application Server V8.0 (the forum is very active). However, what other topics and products/technologies would you like to see talked about here? If you tell me, I'll line up the right people to blog. That is a resolution I can keep.

Happy New Year WebSphereains!

Thursday, November 11, 2010

System Test Team Reports Available on developerWorks

Have you been wondering what the WebSphere system test team has been up to lately? Visit our wiki for access to our collection of test reports. The test reports document results from representative product scenarios that have been validated by IBM system test groups. They cover testing we've done with WebSphere Application Server v7.0, the v8.0 Alpha and Betas, and several Feature Packs.

For example, in a recent report, "Leverage Business Level Applications (BLA) to Improve Management and Operational Capabilities Over Stand-alone Java EE Applications", Feng Yue Li from the WebSphere system test team describes a test scenario that focused on the use of shared libraries within BLAs. She explains how she verified that shared library relationships between BLA composition units work properly when a new version of the BLA asset is rolled out and describes how command assistance can be used with BLAs.

In another recent report, "Test Infrastructure: OSGi FeP and JEE applications", tester Tam Dinh outlines a scenario in which the WebSphere system team deployed, exercised and stressed WebSphere Application Server V7.0 OSGi Feature Pack using three OSGi applications and three JEE applications in a WebSphere Application Server Network Deployment cell.

We'd like to hear your feedback about our work and your ideas about how our testing can be improved. Visit our developerWorks test team wiki and let us know what you think.

Friday, October 8, 2010

New: WebSphere Batch Feature Pack !

Announcing IBM WebSphere Application Server V7 Feature Pack for Modern Batch !

This new feature pack provides support for a Java Batch programming model, offers tools and operational controls for Batch workload execution, enables development and deployment of batch applications, and allows concurrent execution of batch and OLTP workloads.

The Batch Feature Pack is targeted toward developers and basic production deployment. It delivers a subset of the functionality of IBM WebSphere Extended Deployment Compute Grid. Batch applications built using the feature pack are fully upward compatible with the Compute Grid environment.

The Compute Grid product offers advanced features, including support for parallel processing, workload scheduler integration, usage accounting, and more. You can start with the Feature Pack (FeP) for Modern Batch and grow it into a full Compute Grid environment. The Batch Deployment Options Chart outlines the functional continuum among these offerings.



Tuesday, October 5, 2010

Joint WAS XML Feature Pack and DB2 pureXML Article on FpML Lives

I've mentioned this work a few times on the blog, so I wanted to make sure people saw the final article on DeveloperWorks.

Programming XML across the multiple tiers, Part 2: Write efficient Java EE applications that exploit an XML database server

This article uses the example of Financial Products Markup Language (FpML) to show how to program realistic native XML across the Application Server and DB2 pureXML. It shows how you can use one consistent programming model (XQuery) and one consistent data model (XML) across data access, transformation, and filtering across both the mid tier and database tier. Using this one data model which doesn't require mapping to Java objects should increase the agility of your XML centric applications as no mapping code needs to be generated or maintained across both tiers.

Even though the article is based upon FpML (which is really useful to the financial sector), the concept is applicable to all industries that have substantial amounts of XML data.

The article has code attached (both a Rational Application Developer ear project and Eclipse/ANT builds) and database load scripts, so you can play with the code to see how it works. All you need to do is define the JDBC resources to point to your DB2 instance. I also have a virtual image for this based upon the free of charge WebSphere Application Server For Developers and DB2 Express-C in case you're interested.

Monday, September 27, 2010

WebSphere V8.0 Beta Feature Focus Weeks

I hope people have been following the WebSphere Application Server V8.0 Feature Focus weeks on the beta forum. If not, you should check them our here:

IBM WebSphere Application Server V8.0 Beta Forums

Many include demos and extensive information on the features.

Some topics that recently were discussed include XML Application Programming, SIP Servlets, Communication Enabled Applications, Installation on z/OS, JSP 2.2, JAX-RS, Java EE6 Web Services, EJB 3.1, JPA 2.0, Security Enhancements, and Servlet 3.0.

Many other topics have been discussed as well. Just scroll back through the thread to find and comment on many of the new useful features coming in version 8.0.

Friday, August 13, 2010

A view from the road

It's been a very long time since I blogged. Twitter seems to keep me from thinking about blogging as often. Also, I've been hitting a second travel season.

Last week I was at Balisage 2010 talking about Web 2.0 and XML discussing how to introduce MVC frameworks into DOJO (and other Web 2.0 widget libraries) that provides all sorts of interesting value add to DOJO. Also once MVC is in place, XML centric models integrate better into the browser. Specifically I discussed Ubiquity XForms. The goal of this work would be a clean XML story of storage to mid tier joins and query that exposed REST/XML in its original form to the browser. This avoids having to write XML to POJO to JSON conversion routines for data that originates and is stored in XML - a common case in many clients I talk to.

This week, I've been between New York and New Jersey. I've been hearing about how the financial and insurance industries work with XML. I've heard about how enterprise content management systems and data storage systems are closely related. I've heard about how XQuery as a general purpose programming model on top of such data is being used. However, I've heard of challenges that relate in linking systems together. I've also heard that having "hybrid servers" that allow XML to bridge into relational and Java systems and JSON is important. Finally, I built a nice VMware based demo of FpML processing across DB2 pureXML and the WebSphere XML Feature Pack. If you're interested in seeing how to efficiently program native XML end to end (whether you're into FpML or not), let me know and we can arrange a demo.

Friday, July 9, 2010

RAD Tooling for OSGi Applications

RAD V8 Beta 2 is now available with updated support for developing, deploying and testing OSGi Applications using the WAS V7 Feature Pack for OSGi Applications and JPA 2.0. I'll describe some of the new OSGi capabilities of RAD in this post.

Built on top of the latest version of Eclipse (Helios), the RAD V8 Beta provides OSGi tools for enterprise Java developers. While most of the development activities, and hence development tools, for enterprise OSGi applications are common with Java EE there are some new considerations. Primarily, these are around the compile-time classpaths, the authoring of new metadata (the OSGi bundle and application manifests) and, optionally, Blueprint bean definition files. RAD introduces new project types for OSGi Bundle projects and OSGi application projects and a variety of new editors and tools for developing components in these types of projects. OSGi modularity semantics are honored in the project build paths to actively encourage modular design: each project has the scope of a single bundle, with Java package visibility between projects restricted to those packages explicitly imported/exported by the project's bundle manifest. This supports the careful and deliberate exposure of only those Java packages that are intended to be used external to a project . RAD's facet-based configuration enables OSGi projects to be configured as OSGi Web projects or OSGi JPA projects and integrates tools for authoring web.xml, persistence.xml and blueprint.xml. OSGi application projects - representing a complete enterprise application consisting of multiple bundles - can be imported from or exported to enterprise bundle archives, and can be tested and debugged on WAS V7 from the RAD workspace. RAD's SCA development tools are also extended to support "OSGi Applications" as a new implementation type for SCA components. The SCA tools accelerate the assembly of SCA composites; these can include OSGi application components which may selectively expose OSGi services outside the OSGi application and define remote bindings for these services. There's more about the relationship between OSGi services and SCA services here.

One of the quickest ways to explore the new OSGi features in RAD is to import one of the sample applications provided with the WAS V7 feature pack into a RAD workspace. The feature pack's Blog Sample, was described in an earlier post so I'll use that as my example. Start RAD and run the File->Import->OSGi Application (EBA) wizard, enterng the location of the com.ibm.ws.eba.example.blog.eba file (found in the WAS_INSTALL/feature_packs/aries/installableApps directory). Since one of the features this sample is designed to show is the deployment of an application which includes content provisioned from a bundle repository, you also need to make the com.ibm.json.java_1.0.0.jar available in the workspace - which you can do through File->Import->OSGi Bundle. The result is 4 OSGi bundle projects and an OSGi application project in the workspace, with everything correctly resolved.

You can see the relationships between the bundles in this application using RAD's new Bundle Explorer. The figure on the left shows the Bundle Explorer view of the Blog sample application project. Click on the image to enlarge it.

RAD gives you all the syntax assist, refactoring support, and problem quick-fixes you expect as well as new editors for bundle manifests, application manifests and blueprint bean definitions. By encapsulating business logic in POJO Blueprint beans and accessing persistent data through JPA entities, unit testing can be performed with simple frameworks like JUnit without requiring an application server to be running. And, of course, RAD includes integrated support for running and debugging entire OSGi applications on a WAS server, straight from the workspace.

WebSphere Application Server V8.0 Beta

Last week, the beta for WebSphere Application Server V8.0 went live and was announced by Dana Price on the beta forum. There were some initial issues over the weekend with the download, but that is fixed, so if you tried to download -- try it again now.

There is a download for Windows, Linux, AIX, z/OS, Linux for System Z, HP-UX, and Solaris.

You can find out about the features offered in the beta via the following links:



There are far too many features to list here on the blog, so hopefully the above gives you enough reason to give it a spin. See the InfoCenter for further information.

Go ahead, download the beta, try it out and leave feedback on the forum.

Friday, June 25, 2010

Humor for Friday - Java-4-ever

I don't want to post funny videos here too much as I think people come here for technical information. However, this is just too good to not share. There is one slightly NSFW (not safe for work) section. Even mentions XML, so its truly great.

Watch the Java 4-Ever Video

Now on YouTube

Thursday, June 3, 2010

OSGi applications and JPA2 feature pack has gone GA

WooHoo!!!!!!

Releasing any product involves a lot of hard work, sleepless nights and the occasional lost weekend, so you'll understand why I am happy that the feature pack for OSGi Applications and JPA 2 is now GA and can be installed either from the web, or locally, using installation manager.

Some highlights of what we have delivered:
  • Support for development and deployment of enterprise applications using OSGi
  • Support for Enterprise OSGi specs around Web application, Blueprint and JPA
  • The ability to update the individual bundles in an OSGi applications
  • Support for integrating OSGi and Java EE applications using SCA
  • Support for Java Persistence API 2, both from Java EE and OSGi applications
  • Development tooling for OSGi and JPA2 via the Rational Application Developer beta
  • Good performance increase measured using the SPECjEnterprise2010 benchmark.
I could go on and list some of the other cool features, like the bundle repository support for OSGi, and the JPA2 criteria API, but some of they have been discussed on the blog already, and then I wouldn't have an excuse to write more about them later.

Download, use, enjoy!
Alasdair

P.S. There is an iFix available for the feature pack and we recommend you install it.
P.P.S. You'll need to have 7.0.0.9 of the application server and JDK to install the feature pack.

Sunday, May 30, 2010

The Cure for XML in Web 2.0?

Earlier, I blogged about the Pain of XML in Web 2.0. I alluded to not being happy with the answer I ended up with. I'm happy to say that I'll finally be talking about a possible solution. As you see here, I have submitted a paper for the Balisage 2010 Conference entitled Where XForms meets the glass: Bridging between data and interaction design along with Charles Wiecha and Rahul Akolkar.

Here is the abstract:

XForms offers a model-view framework for XML applications. Some developers take a data-centric approach, developing XForms applications by first specifying abstract operations on data and then gradually giving those operations a concrete user interface using XForms widgets. Other developers start from the user interface and develop the MVC model only as far as is needed to support the desired user experience. Tools and design methods suitable for one group may be unhelpful (at best) for the other. We explore a way to bridge this divide by working within the conventions of existing Ajax frameworks such as Dojo.


Interested? Let me know and we can get a review copy of the paper to you. I have talked to many clients that want to integrate their meta data driven XML dominant data to the Web 2.0 work with DOJO and run into the impedance mismatch wall. Hopefully that wall will be coming down soon.

BTW, if you'd like to attend this great conference to hear about this topic and many others on the jam packed agenda, here is a great link to use to convince your management to let you join us in Montreal.

Thursday, May 27, 2010

XQuery: Powerful, Simple, Cool .. "Demo"

At IBM Impact this year, I did talks about the XML Feature Pack as well as basic introduction to the XPath 2.0, XSLT 2.0 and XQuery 1.0. I think one of the most useful parts of my talk was when I demoed code in XQuery. I found that people really saw the light (how simple and fully functioned XQuery is) once people saw the code in a useful application. Also, people that were experienced with XPath 1.0 appreciated the new features and people who had experience with XSLT 1.0 appreciated the syntax (closer to imperative coding). The application I used in the demo was the download stats program I have blogged about before. Let me take a second to do the same "demo" here.

First, I have an XML input file of all the downloads over a certain time period. That XML file could come from a web services, a JMS message, or be loaded from a XML database. The data looks something like:


<?xml version="1.0" encoding="UTF-8"?>
<downloads>
<download>
<transaction>1</transaction>
<userid>user1</userid>
<uniqueCustomerId>uid-1</uniqueCustomerId>
<filename>xml_and_import_repositories.zip</filename>
<name>Mr. Andrew Spyker</name>
<email>user@email.com</email>
<companyname>IBM</companyname>
<datedownloaded>2009-11-20</datedownloaded>
</download>
<!-- more download records repeating -->
</downloads>


First I want to quickly get rid of all downloads that have "education" in the filename. Next I want to split the downloads that come from IBM'ers (email or company has some version of IBM in it) vs. the downloads that come from clients. Of those groups, I want to quickly group repeat downloaders (by uniqueCustomerId). I won't include it here, but I've show how to write some of this with Java and DOM in the past. It's sufficient to say that this code is very complex (imagine all the loops through the data you'd write for each of these steps). Let's look at these steps in XQuery:


(: Quickly get rid of education downloads :)
declare variable $allNonEducationDownloads := /downloads/download[not(contains(filename, '/education/'))];

(: Split the IBM downloads from non-IBM downloads :)
declare variable $allIBMDownloads :=
$allNonEducationDownloads[contains(upper-case(email), 'IBM')] |
$allNonEducationDownloads[contains(upper-case(companyname), 'IBM')] |
$allNonEducationDownloads[contains(upper-case(companyname), 'INTERNATIONAL BUSINESS MACHINES')];

(: Get the unique IBM downloader id's :)
declare variable $allIBMUniqueIds := distinct-values($allIBMDownloads/uniqueCustomerId);

(: Get the non-IBM downloads :)
declare variable $allNonIBMDownloads := $allNonEducationDownloads except $allIBMDownloads;

(: Get the unique non-IBM downloader id's :)
declare variable $allINonIBMUniqueIds := distinct-values($allNonIBMDownloads/uniqueCustomerId);


I think the most powerful line of the above code is the "except" statement. In that one quick statement, I can quickly express that we want to take all the downloads and remove the IBM downloads which leaves us with the non-IBM downloads. I think it's quite impressive that XQuery expresses the above statements in about the same amount of lines as the English language I used to describe the requirements.

Additionally, since you are telling the runtime what you want to do instead of how you want to do it, our runtime can aggressively optimize the data access in ways that we couldn't if we had to try to understand the Java byte codes were doing on top of the DOM programming model. Also, since XQuery is functional (the above variables are final) we could span this to multi-core more safely than imperative code as we can guarantee there are no side-effects. This is why, as a performance guy, I think declarative languages are a key to the future of performance.

Back to the code. For people used to XPath 1.0 and its lack of all the built-in schema types, dealing with things as simple as dates was problematic (they were just strings). Here are a few functions that show, with schema awareness, XPath 2.0 and XQuery 1.0 are much more powerful than before:


declare function my:downloadsInDateRange($downloads, $startDate as xs:date, $endDate as xs:date) {
$downloads[xs:date(datedownloaded) >= $startDate and xs:date(datedownloaded) <= $endDate]
};

declare function my:codeDownloadsInDateRange($downloads, $startDate as xs:date, $endDate as xs:date) {
let $onlyCodeDownloads := my:onlyCodeDownloads($downloads)
return my:downloadsInDateRange($onlyCodeDownloads, $startDate, $endDate)
};


These two functions give me a quick way to look for "code" downloads within a date range. In the first function, it's very easy to understand that this functions take the downloads and returns only the subset that has a datedownloaded that is after the start date and before the end date. In the second function, you can see it's easy to call the first function. At this point, I think most Java programmers might be saying "this isn't like what I expected based on my previous work with XSLT". While XSLT is a great language for transformation (XSLT 2.0 even better), I think XQuery gets a little closer to a general purpose language with the ability to declare functions and variables in a more terse syntax.

Finally, let's cover two more important powerful features - FLOWR and output construction. Once I have sliced and diced the data, I need to output the data into a XML report. XQuery gives you a very nice way to mix XML and declarative code as shown below:


declare function my:downloadsByUniqid($uniqid, $downloads) {
for $id in $uniqid
let
$allDownloadsByUniqueId := $downloads[uniqueCustomerId = $id],
$allCodeDownloadsByUniqueId := $downloads[uniqueCustomerId = $id and (contains(filename, 'repositories'))]
return
<downloadById id="{ $id }" codeDownloads="{ count($allCodeDownloadsByUniqueId) }" >
<name>{ data($allDownloadsByUniqueId[1]/name) }</name>
<companyName>{ data($allDownloadsByUniqueId[1]/companyname) }</companyName>
<codeDownloads>
{
for $download in $allCodeDownloadsByUniqueId order by $download/datedownloaded return
<download>
<filename>{ data($download/filename) }</filename>
<datedownloaded>{ data($download/datedownloaded) }</datedownloaded>
</download>
}
</codeDownloads>
</downloadById>
};



This shows how you can create new XML documents and quickly mix in XQuery code. Some people I've talked to think this looks like scripting languages in terms of simplicity. Also, you'll see a For ($id in $uniqid) Let ($allDownloadsByUniqueId, ohters) Return (downloadsById). These three parts make up part of what people call FLOWR (and pronounce flower) which stands for for, let, order by, where, return. The FLOWR statement is a very powerful construct -- able to do all the sorts of joins of data you're used to in SQL -- but in this example I've chosen to show how it can be used to simplify code in the general case where joining data wasn't the focus. For Java people, think of it as a much more powerful looping construct that integrates all the power of SQL for XML.

In the end, I have a 200 line program that takes all the download reports and organizes them by unique IBM vs. unique non-IBM ids and produces a month by month summary. I'd be surprised if you could come up with anything shorter and more maintainable that worked with Java and DOM. I hope this "demo" encourages you to consider using XQuery in your next project where you need to work with data.

Finally, if you find people trying to convince you that XQuery isn't capable enough to be a general language, take a look at a complete ray tracer written in XQuery in a mere 300 lines of code (a real statement of XQuery's power and brevity).

PS. You can download this XQuery program here and some sample input here. You can run them by getting the XML Feature Pack thin client here. The thin client is a general purpose Java based XQuery processor that you can use for evaluation and in production when used with the WebSphere Application Server. All you need to do is download the thin client, unzip and run the below command:


.\executeXQuery.bat -input downloads-fake.xml summary.xq

Wednesday, May 26, 2010

Why the -outputfile switch in XML Thin Client is useful

A simple tip...

I was recently working with a set of files that contained non-English Unicode characters and trying to process the data with XSLT 2.0 and XQuery 1.0. I was using the Thin Client for XML that is part of the XML Feature Pack which offers J2SE and command line invocation options for XSLT and XQuery when used in a WebSphere environment.

I did something like:


.\executeXSLT.bat -input input.xml stylesheet.xslt > temp.xml
.\executeXQuery.bat -input temp.xml query.xq > final.xml


And this resulted in something like:


... executeXSLT "works" fine ...
... executeXQuery "fails" with ...
An invalid XML character (Unicode: 0x[8D,3F,E6,8D]) was found in the element content of the document
.
An invalid XML character (Unicode: 0x[8D,3F,E6,8D]) was found in the element content of the document
.


I figured something was wrong with the encodings in the XSLT output method or the xml encoding of the files themselves or -- worse yet -- something wrong with our processor. After some quick thinking by my excellent team, they had me replace the output redirection (where my OS and console got a chance to see/mess with the data between the processor and temp.xml) with the -outputfile option (which allows the processor to directly write to the file) like:


.\executeXSLT.bat -input input.xml -outputfile temp.xml stylesheet.xslt
.\executeXQuery.bat -input temp.xml -outputfile final.xml query.xq


Problem solved. No corruption of the data.

Lesson learned: Keep all the data inside of the processor and don't introduce things (like the Windows Console) into the pipeline that won't honor (or know) the encoding.