FireworksColdFusionDreamweaverFreehandFlashMXHome
Latest New Content

Latest Free Content
View All
Free Content
Accessibility
CMX Learning Guides
Hosted by enterhost

Simplify Your XML Development with XMLSpy

By: Danny Patterson

Page 1 of 2

Set for printing

Next

Editing XML is often something that developers take for granted. Since XML is text-based, developers can create and edit XML documents in the text editor of their choice. However, there are some use cases that require a dedicated XML editor. XMLSpy from Altova is just such an editor. It is designed specifically for working with different types of XML. And believe me, once you've used this tool, you'll wonder how you got along without it.

NOTE: This article will assume you are using XMLSpy Professional or Enterprise. A free version of XMLSpy is available for download on Altova's web site. You can activate the Professional features within the free version for a one-day trial.

I am primarily a Flash and ColdFusion developer, therefore, most of the complex XML tasks I do are those that can be done from within those languages. I will be covering three different features of XMLSpy that I use on a daily or weekly basis: XPath in Flash and ColdFusion, XSLT in ColdFusion, and XML Schema in ColdFusion.

Sample XML Data

All of the examples in this article will use the following XML document:

<store>
  <category name="first">
    <product id="0001">
      <name>Product One</name>
      <price>5.50</price>
    </product>
    <product id="0002">
      <name>Product Two</name>
      <price>10.00</price>
    </product>
    <product id="0003">
      <name>Product Three</name>
      <price>12.75</price>
    </product>
  </category>
  <category name="second">
    <product id="0004">
      <name>Product Four</name>
      <price>35.50</price>
    </product>
    <product id="0005">
      <name>Product Five</name>
      <price>42.00</price>
    </product>
    <product id="0006">
      <name>Product Six</name>
      <price>50.00</price>
    </product>
  </category>
</store>

Listing 1  Sample XML document used throughout this article (data.xml).

To obtain the sample files, click Download Support Files at the bottom of this page and extract the zip to a folder on your computer.

XPath

XPath is a part of the XSLT Specification and is used to "query" portions of an XML document. This is a very valuable tool for developers of many different scripting languages, but most of my experience using XPath is in ActionScript and ColdFusion. For more information about using XPath in ActionScript, check out "Using the XFactorStudio XPath Classes in Flash." XPath in ColdFusion is implemented with the xmlSearch function.

The most common thing I use XMLSpy for is creating XPath expressions. There is a tool in XMLSpy called Evaluate XPath. This feature is not available in the free home edition, but it is well worth the upgrade. This tool enables you to test the result of an XPath expression against the current XML document. While this probably isn't necessary for simple XPath expressions, it is very handy when evaluating complex expressions. This can also be helpful if you are trying to find something in a very large XML document. To get to the XPath Evaluator click on XML > Evaluate XPath in the top menu. The following screen shot is what the Evaluator looks like and how it can be used to test your expressions:


Figure 1  Screenshot of the XPath evaluator in XMLSpy.

The following code samples show how this expression could be implemented in ActionScript and ColdFusion, respectively:

import com.xfactorstudio.xml.xpath.XPath;
var nodes:Array = XPath.selectNodes(xmlData, "/store/category[@name = "first"]/product[price >= 10]");

Listing 2  Sample XPath code in ActionScript using the XFactorStudio class library.

<cfset nodes = xmlSearch(xmlData, '/store/category[@name = "first"]/product[price >= 10]') />

Listing 3  Sample XPath code in ColdFusion using the built-in xmlSearch function.

Page 1 of 2 1 2 Next


download
Download Support Files


Keywords
Altova, XMLSpy, MapForce, StyleVision, XPath, Schema, XSLT, XML, Flash, ActionScript, ColdFusion, XFactorStudio