Easily Parse XML

How to Easily Parse XML

XML is used a lot on the internet and in business .  For instance, it is used by Blogs in a format called Real Simple Syndication, or RSS , to allow people to read a blog without actually visiting the blog’s website.  XML is also used to store reference information in web services and configuration files on many open and closed source products such as Instant Messager servers , web servers , and Oracle’s SQL Developer .

Since XML has become so popular in recent years, there are tools for most languages that make XML pretty easy to parse and handle.

Here are 2 tools you can use to parse XML:

1)  MagpieRSS for PHP

MagpieRSS is a great way to parse almost any format of XML clearly and concisely.  Simply include the file "rss_fetch.inc" and then access the entire XML feed as an array.

From their example page:

<item rdf:about="http://protest.net/NorthEast/calendrome.cgi?span=event&ID=210257">
<title>Weekly Peace Vigil</title>
<link>http://protest.net/NorthEast/calendrome.cgi?span=event&ID=210257</link>
<description>Wear a white ribbon</description>
<dc:subject>Peace</dc:subject>
<ev:startdate>2002-06-01T11:00:00</ev:startdate>
<ev:location>Northampton, MA</ev:location>
<ev:enddate>2002-06-01T12:00:00</ev:enddate>
<ev:type>Protest</ev:type>
</item>

Get's parsed to:

array(
title => 'Weekly Peace Vigil',
link => 'http://protest.net/NorthEast/calendrome.cgi?span=event&ID=210257',
description => 'Wear a white ribbon',
dc => array (
subject => 'Peace'
),
ev => array (
startdate => '2002-06-01T11:00:00',
enddate => '2002-06-01T12:00:00',
type => 'Protest',
location => 'Northampton, MA'
)
);

2) RSSutils Jar and Tag Library for Java

First, download and unpack RSSutils from here
.  Next copy 
rssutils.jar

and rsstaglib.tld
into your 
/WEB-INF/lib
directory.  Then add the following to web.xml
:


    <taglib>
<taglib-uri>/WEB-INF/lib/rssutils.tld</taglib-uri>
<taglib-location>/WEB-INF/lib/rssutils.tld</taglib-location>
</taglib>

Now you can reference the tag library in your JSP page similar to the following example:

    <%@ taglib uri="/WEB-INF/lib/rssutils.tld" prefix="rss" %>

<rss:feed
url="http://url/to/xml.xml" feedId="xmlFeed"/>
<b>Image: </b><rss:channelImage feedId="xmlFeed"/><br>
<b>Title: </b><rss:channelTitle feedId="xmlFeed"/><br>
<b>Link: </b><rss:channelLink feedId="xmlFeed" asLink="true"/><br>
<b>Description: </b><rss:channelDescription feedId="xmlFeed"/><br>
<ul>
<rss:forEachItem feedId="xmlFeed">
<li><rss:itemDescription feedId="xmlFeed"/><br><br>
</rss:forEachItem>
</ul>


Make sure you come up with a unique feedId
to use throughout the page, especially if you are going to be parsing multiple feeds on a single page.  Read a much longer rssutils tutorial here
.

Rounded Corners with The GIMP

Creating Round Corners

These days more often than not, people want rounded corners instead of the regular squares on images for websites, print work, and photographs.

It is true that this can be done in Photoshop and other expensive programs .  However, why pay all that money when it can be done very easily with the open source graphic editing tool, The GIMP .

Step 1: Download The GIMP and Install

The GIMP runs on any operating system so you can use it on Windows XP, Windows Vista, Linux, and Mac OS X.  Download The GIMP and follow the included instructions to install.  Installation should be very similar to any other install.

Step 2: Open and Create Project Canvas

First, open up The GIMP in your respective applications folder and create a new project (say 800 x 600 pixels, the average website size).

Next, click on the Rectangle Select Tool in the Toolbar .  If you don’t know what this tool looks like, mouse over each item until you find it.  Hint: It is usually the first item in the Toolbox.

Step 3: Create a Rectangle

With the Rectangle Select Tool selected, draw a rectangle on the canvas.

Step 4: Change the Color

If you want to change the color of the rectangle, you should do this now by selecting a new Foreground Color and clicking on the Paint Bucket Tool (Hint: it is the one that looks like the paint bucket ).  Once you have selected a color and the Paint Bucket, click anywhere within the rectangle.

Step 5: Round the Corners

Next, click on Select > Round Rectangle in the top menu above the canvas.  Play with the radius settings until you get it just right.  You can undo the rounded rectangle you just created at any time by selecting Edit > Undo .  Remember, the larger the radius settings, the more round your rectangle will be.

Call Web Service in Java

Consume a Web Service with Java

As I stated before, calling a web service in .Net is easy .  However, using a Java Web Service is a little more difficult .  This is not because .Net is superior to Java, but instead because of the various standards that Java allows for since it is open sourced.  In other words, Java can be extended and new standards can be developed, whereas Microsoft keeps tight control over their beloved .Net framework.

Step 1:  Download and Install NetBeans

First you must download and Java IDE such as Netbeans , Eclipse , or Oracle’s JDeveloper .  I have used all three and I would recommend NetBeans because I found that JDeveloper was a little behind on certian standards and Eclipse requires that you install additional plugins to allow you to develop with web services.  However, the latest version of NetBeans (6.5 as of this writing) comes with everything you need to develop and consume web services, including a choice of embedded web servers for development.

Step 2: Create a Web Project and Web Service Client

Next, create a new Web Project by clicking File > New and selecting Web Project from the list.

Once it builds your project, you must tell NetBeans what type of project you are developing.  You can do this by right clicking your newly created Project in the Projects pane and selecting New > Web Service Client .  If I remember correctly, this is where a wizard will prompt you for the Web Service WSDL that you are wanting to call .

WSDL stands for Web Service Definition Language and is a document that is generated when you build a web service to tell the applications that want to use it what methods are available to use.

Step 3: Call Web Service

Once your project finishes generating the local methods for calling the external web service, you should see a tree option under your project entitled Source Packages . Open this tree item and all items below it and you should see a Java file "*.java"Double click this so it opens, then right click > Web Service Client Resources > Call Web Service Operation .

Step 4: Modify and Test

Once the generation is completed, you should be able to reference the web service objects similar to the following:

WsNameOfService port =   service.getWsNameOfServicePort();
boolean tf;
tf = port.isReady();

out.println("Result: " + tf);

Enjoy and Good Luck!

Note: If your not getting the same menu items as me then you probably created the wrong project type in the first couple of steps.  For instance, NetBeans may not allow you to create a Web Service Client in a regular Java project.  Start over with a new project and ensure you are selecting the correct project types.

.Net Consume Web Service

Consume Web Service with .Net

During the past 8 months, I have been playing with web services quite a bit – both calling and developing web services for my employer.  However, I had some trouble along the way finding information on the different standards of web services (such as JAX-WS and JAX-RPC ), implementing those web services on the server (Jboss) , and testing the services by writing a web service client (VB.Net) .

So I thought documenting the information I have collected would be useful for others attempting the same thing.  The next series of posts will show you how to write, deploy, and consume web services using a combination of .Net and Java.

Consume a Web Service in .NET

Calling a web service in Microsoft .Net framework is super easy.  Simply open a new or existing project, click Project > Add Web Reference , then enter the URL to the web service’s WSDL .

A WSDL is an XML document that is used to define a web service , such as Method Names and Parameters for those Methods.  Don’t worry, you usually don’t have to write this document by hand.  Yes, the programming gods have smiled upon us.  Most IDE editors will do this for you including Visual Studio and NetBeans .

After entering the URL as suggested above, just follow the wizard steps and .Net will take care of the rest for you.

Once complete, you should see Web References in the Solution Explorer pane in Visual Studio.  You can edit the Reference Name and URL in the Properties pane by clicking on the web service reference (whatever you named it) under Web References .

Now you can reference the web service object that you just created by typing "WhateverYouNamedIt. "

Go ahead and give it a shot!