Workload Manager Policy in XML Format – Part II

(Originally posted 2009-04-07.)

In Workload Manager Policy in XML Format – Part I I showed you how you can use PHP to extract Classification Rules information from the WLM Service Definition (once converted to XML format).

This post gives an example of extracting a different set of information from the XML Service Definition, using javascript and, in particular, XMLHttpRequest (sometimes known as XHR).

There is a slightly ulterior motive here: Acquainting mainframe people with some of the more modern web techniques. (I’m hoping you’ll explore some of them for yourselves.)

Here’s some sample code:

<html><body><h2>Workloads</h2><ul id="workloads"></ul><script type="text/javascript">  var req = new XMLHttpRequest();'GET', 'wlmpolicy.xml', true)  req.onreadystatechange = function (aEvt)  {    if (req.readyState == 4)    {      if(req.status == 200)      {        DOM=req.responseXML;                // Get list of workloads        workloads=DOM.getElementsByTagName("Workload")                // Add a list item for each workload        ul=document.getElementById("workloads")        for(w=0;w<workloads.length;w++)        {          // Get workload name          nameNode=workloads[w].getElementsByTagName("Name")[0].firstChild          workloadName=nameNode.nodeValue

// Get workload description descNode=workloads[w].getElementsByTagName("Description")[0].firstChild workloadDesc=descNode.nodeValue

// Create list item and add workload name / desc to it li=document.createElement("li") liText=document.createTextNode(workloadName+" - "+workloadDesc) li.appendChild(liText) // List item to the list ul.appendChild(li) } } } } req.send(null);</script></body></html>

Now, hopefully that wasn’t too intimidating: If you have a webserver to stick your XML on try it for yourself: The only thing you’ll need to change is the target URL in the XMLHttpRequest.

Most of the code is designed to fire – as a block – when the XML document is retrieved. It parses the returned XML, looking for “<Workload>” elements. The list of those is in array “workloads”.

For each of the workloads it looks for “<Name>” and “<Description>” elements and retrieves the text associated with them.

Finally, for each workload, a new “<li>” tag is created and populated with the workload’s name and description.

Thus the code sample prints a list of workloads and their descriptions.

There’s obviously a lot more in the WLM Service Description. I’ve shown you two techniques for parsing it. The simplest thing to do next is to convert your own WLM Service Definition to XML and browse it with a text editor. (On Windows I’m using Notepad++ but any editor will do, preferably one that syntax highlights XML).

Published by Martin Packer


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: