In the first article of this two-parter, we discussed collecting EMC Symmetrix information using SYMCLI commands. The XML output provides greater flexibility and ease of scripting for manipulating Symmetrix output. In this article we will look at using an XML manipulation tool in order to extract something useful from the XML output.
One of the simplest and most transportable methods for processing XML is to use XSLT (Extensible Stylesheet Language Transformations). XSLT is in fact a programming language that can be used to process XML documents. You can process XML with XSLT using platform independent tools. For my examples, I’ve used the MSXML 4.0 (Microsoft XML Core Services) and a free XML XSLT command line utility, msxsl.exe, downloadable from the Microsoft website. This utility allows me to specify the source XML file and the XSLT file to be applied to it. Search for msxsl.exe at http://search.microsoft.com/search/search.aspx?st=b&View=en-us to download the utility.
How do we write XSLT? The following example of XSLT extracts the Symmetrix ID’s and product models from a Symmetrix XML “SYMCFG LIST” command:
The logic to this code is as follows;
1. Match the root XML keyword SymCLI_ML.
2. For each “Symmetrix” node that is located, write out the value of the @id and @product_model variables.
You can see from the XML fragment below, that the parameters @id and @product_model refer to attributes of the Symmetrix node and we have simply extracted the data we want to display.
By default, the XML output is expected to be HTML, so I’ve chosen to format the data as a table in order to improve the readability, which viewed in a web browser produces the following table with the sample XML input:
|Symmetrix ID||Serial Number|
What’s clear is that with a very small amount of coding, we can extract details from our XML file. I used the msxsl.exe file from Microsoft to run this command as follows:
msxsl example1.xml example1.xsl -o example1.html
This command takes the XML data in example1.xml, uses the XSLT in example1.xsl (our figure 1 above) and outputs the data to example1.html, which can then be viewed by the web browser.
Our first example demonstrated how easy it is to extract data from XML. Let’s do something more useful this time, taking as sample output the details on all volumes from a SYMDEV LIST command and producing a text file of each device, its type and capacity, sorted by type, for totalling by a script:
This code contains a few new items. Firstly, we’ve specified the format of the output and that it is not intended for use as a web page but as plain code (line 3). Next we define a variable to insert a carriage return and line feed after each line we output (line 4). For each device we locate (the “for-each”) keyword, we output the device name (dev_name), the type of device (configuration) and the capacity (megabytes). Note how the capacity is a separate child node in XML, so we need to specify the “megabytes” value by referencing the node and the value (“Capacity/@megabytes”).
The sample input and output for this code is quite long and can be located through the following links:
As you can see, with some simple code, we can extract data in a more use-friendly format, for later processing by a script. If the format of the original data changes, then the XML will continue to produce the data in the same way to a script, making data maintenance much simpler. Through a little effort you can easily process the data from SYMCLI commands to provide data to web pages or processing by scripts.
If you’ve created XML you would like to share with others, why not post them on our forum. Over the coming weeks, I’ll post some of my more useful XML there for free use in your scripts.
Useful ReferencesYou can find out more information on XML through one of the following links:
- Microsoft XML Information
- The MS XML SDK Documentation
- A useful site for XML code
- A Java-based XSLT tool