Posts tagged as:

xmlbeans

Daily del.icio.us for Jul 14, 2007 through Jul 15, 2007

by Vinny Carpenter on July 15, 2007

Tags: , , , , , , , , , , , , , , , , , , , , , , ,

Related posts

Daily del.icio.us for Mar 17, 2007

by Vinny Carpenter on March 17, 2007

  • SXC - Simple XML Compiler - SXC (Simple XML Compiler) allows you to created optimized parsers and writers for XML. Through a declarative API you're able to tell SXC what type of XML to expect and what actions to associate with it.
  • On the Stre@m - Flex has become more accessible - The Flex module for Apache and IIS provides web-tier compilation of MXML and ActionScript files on Apache and IIS web servers.
  • Assessing the Survivors of the Java IDE Wars - For enterprise development, I'd say IDEA wins out with its rich support for both J2EE and Java EE 5, followed closely by NetBeans (which also does an impressive job here), and last is Eclipse/MyEclipse (mostly due to their current lack of support for Java
  • An XQuery Servlet for RESTful Data Services - This paper shows how to use XQuery for data integration, and how to expose an XQuery as a RESTful data service using a Java servlet
  • Control.Tabs : Projects : LivePipe - Control.Tabs is a javascript library for creating accessible, flexible & unobtrusive tabbed interfaces in your applications or pages.
Tags: , , , , , , , , , , , , , , , , , , , , , , , , ,

Related posts

Life is beautiful with XMLBeans and XStream

by Vinny Carpenter on January 30, 2006

XML creation, parsing and processing with Java has gotten so much easier with tools like XMLBeans, XStream and many other such tools. I personally love XMLBeans and XStream and I try to use them for all of my XML processing needs. While they both consume XML, they solve different problems. XMLBeans allows you to process XML by binding it to Java types using XML schema that has been compiled to generate Java types that represent schema types. XStream on the other hand allows you to serialize objects to XML and back again using special reflective secret sauce.

I've been using these tools for many years now and so you tend to forget just how useful and powerful they are and how productive they make you. Case in point – A friend of mine came to me for help. He was building an application that would allow him to resale items from Amazon on his site and he wanted to use the Amazon eCommerce Web Services to search for products programmatically and update a local database that housed his content. Having played with Amazon E-Commerce Service (ECS) before, I offered to write up a simple application that would make the Web Services call, process the results and present them back to you.

Amazon's ECS is an API that allows you to access Amazon data and functionality through a Web site or Web-enabled application. ECS follows the standard Web services model: users of the service request data through XML over HTTP (REST) or SOAP and data is returned by the service as an XML-formatted stream of text. In addition to the WSDL, ECS also provides XML schemas for validating the XML output of REST requests. So I decide to use XMLBeans to create my type system using the XML Schema provided by Amazon. XMLBeans provides you with a utility (scomp) to compile your schema into Java XMLBeans classes and metadata. To generate the Java code, use the following command:

scomp –jar amznws.jar AWSECommerceService.xsd

This generates a jar file named amznws.jar, which will contain all of the code needed to bind an XML instance to the Java types representing your schema. In my application, I use HttpClient to make my REST request and then use the XMLBeans generated jar file to process the result. Here's a snippet of code from my sample class:

[code lang="java"]

if (StringUtils.isNotBlank(searchCriteria)) {
String url = "http://webservices.amazon.com/onca/xml?Service=AWSECommerceService&" +
"AWSAccessKeyId=*YOUR_KEY*&AssociateTag=*YOUR_TAG*&Operation=ItemSearch&SearchIndex=Books&" +
"Keywords=" + searchCriteria + "&ResponseGroup=Large,Images";

GetMethod method = new GetMethod(url);
List results = new ArrayList();

try {
int statusCode = client.executeMethod(method);

if (statusCode != HttpStatus.SC_OK) {
log.error("Method failed: " + method.getStatusLine());
}

// Read the response body.
InputStream in = method.getResponseBodyAsStream();
String xmlPayload = parseISToString(in);

// Set up the validation error listener.
ArrayList validationErrors = new ArrayList();
XmlOptions validationOptions = new XmlOptions();
validationOptions.setErrorListener(validationErrors);

ItemSearchResponseDocument items = ItemSearchResponseDocument.Factory.parse(xmlPayload);

if (items != null) {

ItemsDocument.Items[] itemsArray = items.getItemSearchResponse().getItemsArray();
for (int i = 0; i < itemsArray.length; i++) {
AmazonWSObject amzn = processResults(itemsArray, i);
results.add(i, amzn);
}

// During validation, errors are added to the ArrayList
boolean isValid = items.validate(validationOptions);

// Print the errors if the XML is invalid.
if (!isValid) {
for (Object validationError : validationErrors) {
log.error(">> " + validationError + "\n");
}
}
} else {
log.error("Search returned no results");
}
} catch (HttpException e) {
log.error("Fatal protocol violation: " + e.getMessage());
} catch (IOException e) {
log.error("Fatal transport error: " + e.getMessage());
log.error(e.toString());
} catch (XmlException e) {
log.error(e.toString());
} finally {
method.releaseConnection();
}

return results;
} else {
return null;
}

[/code]

As you can tell, HttpClient makes the REST call a snap and XMLBeans makes processing the results easy as well. In total, I spent 3-4 hours getting the application working and a lot of the time was spent figuring out the data set returned from Amazon and trying to come up with a meaningful example. Here is a zip file with the IDEA project that has all the stuff needed to make this work including a simple JSP and a JUnit test class.

Links of Interest:

Tags: , , , , , , , , , , , ,

Related posts

Discover how XMLBeans is revolutionizing data binding

by Vinny Carpenter on September 28, 2004

Get an in-depth look at the features and functionality of XMLBeans. This article introduces the technology with a simple example, takes you through the step-by-step process of compilation and binding, and discusses advanced features like XML cursors, tokens, and XQuery expressions. It also discusses how XMLBeans is more powerful than other XML-Java technology data binding techniques.

http://www-106.ibm.com/developerworks/xml/library/x-beans1/

Tags: , , , ,

Related posts

BEA looks to open-source part of WebLogic Workshop

by Vinny Carpenter on May 10, 2004

Just saw this article on eWeek. The article states that BEA is slated to announce plans to open-source portions of its WebLogic Workshop tool at the upcoming eWorld conference. BEA has a pretty good record of supporting open-source software and the XMLBeans project is a good example of that. I think the support of AspectWerkz is another example.

If BEA does open-source some of the features of Workshop, this could really help the Eclipse Webtools platform project. I am not a Workshop power user by any stretch of the imagination, but it still does have some pretty cool features. It would be nice to incorporate things like page flow and some of the other cool features into the Eclipse webtools product - Give IntelliJ's Fabrique a run for the money.

Tags: , , , , ,

Related posts

XMLBeans arrive @ Apache

by Vinny Carpenter on September 16, 2003

Just caught this email in my mailbox and I'm really excited to see this development. I was blogging about this topic earlier and I am really glad to see this happen.


—–Original Message—–
From: Cliff Schmidt [mailto:cliff@bea.com]
Sent: Monday, September 15, 2003 9:05 PM
To: announce@incubator.apache.org; announcements@xml.apache.org; general@incubator.apache.org; general@xml.apache.org; announcements@jakarta.apache.org
Cc: pmc@xml.apache.org; pmc@incubator.apache.org
Subject: XMLBeans code has been checked in!

Thanks to the help of Brian Behlendorf, Ted Leung, Steven Noels, Greg Stein, and several other friendly folks within Apache, BEA has just checked the entire XMLBeans source code into cvs.apache.org [1]. It's now available to everyone who wants to be involved — just click on 1+ of the links below [2] [3][4][5] and join the exciting world of XML and Java binding!

Thanks,
Cliff

[1] http://nagoya.apache.org/eyebrowse/ReadMsg?listName=xmlbeans-dev@xml.apache.org&msgNo=64

XMLBeans Web site (soon to be updated with binaries, docs, and much more): [2] http://xml.apache.org/xmlbeans/

Subscription links:
[3] mailto:xmlbeans-user-subscribe@xml.apache.org
[4] mailto:xmlbeans-dev-subscribe@xml.apache.org
[5] mailto:xmlbeans-cvs-subscribe@xml.apache.org

Kudos to BEA for donating XMLBeans to the Apache Group and kudos to Apache for accepting it. I am really excited about participating in this project and I'm downloading the source as we speak.

Tags: ,

Related posts

XML Beans: The Best of Both Worlds

by Vinny Carpenter on July 1, 2003

BEA's dev2dev site has an article titled XML Beans: The Best of Both Worlds on their cover page. XMLBeans is a pretty interesting technology from BEA that provides easy navigation of XML data using cursors or XQuery statements. In addition, Java classes representing the XML document is automatically generated based on the XML Schema provided. These generated Java classes enable easy read/write access to XML information and enforce XML Schema constraints. Pretty neat idea and it's fast. And the support for XML Schema is pretty nice.

This brings up an issue as Sun has been pushing JAXB as the standard API/tool that automates the mapping between XML documents and Java objects. Will these 2 products directly compete or will BEA support JAXB completely in their product line? BEA has typically had a really good record of supporting and leading the charge on creation of new standards via. the JCP. Hitesh Seth, the author talks about it in his article and I second his hope that these initiatives converge at some point. ok.. Now back to Hibernate :)

Tags: , , , , , , ,

Related posts