Posts Tagged ‘XML’

Case-sensitivity with Coldfusion and XML

Sunday, November 14th, 2010

This is really just a note about intermingling a case-insensitive language like Coldfusion with a case-sensitive language like XML. Sometimes I get so used to not having to pay attention to case when something goes wrong, that figuring out a simple issue that does have to do with case-sensitivity really throws me for a loop. The issue I ran into involved using the xmlSearch() function.

I used this function to search on an XML doc and the search kept returning an empty array. For a moment I thought for sure my xPath was incorrect, but further research showed it to be accurate. For some reason I just couldn’t get to a certain node. Of course, the issue turned out to be that I simply didn’t case my xPath correctly. For example my xPath may have looked like “//root/mynode”. The actual node I was trying to get in the XML doc was myNode.

Because I deal so much with Coldfusion I feel my immediate reaction to an xPath issue was that it was either wrong, or there was a misspelling. It really took a few minutes to realize that the path was correct as well as the spelling. What was incorrect was the case. Correcting the case, of course, resolved the issue.

So something to keep in mind, that while working within the world of Coldfusion case is meaningful only in terms of readability and following standards. However, when using Coldfusion with other (possibly case-sensitive) languages like XML we have to switch our brains into a different mode and start troubleshooting with character case in mind.

Using SoapUI to work with SOAP and WSDL request / responses

Tuesday, November 9th, 2010

My use of the software SoapUI has so far been minimal although I intend to further explore its capabilities, and a quick look at their website indicates that there are many. Currently I have been working with some Web Services Description Language (WSDL) documents utilizing SOAP for the service messaging. While true, a WSDL will contain all that one needs to know to invoke the web service, what if – you may ask, there was a program that could take that WSDL and create mock SOAP requests and responses based on the guidelines laid out in the WSDL.

Well, this is where the SoapUI comes into play (and as I previously stated it appears to do many other awesome things). A colleague of mine recommended using it, and it is certainly a program I will continue to utilize as it does create an easy to read set of mock requests and responses that significantly reduces the amount of time it takes to plan out a program utilizing a complex set of web services to perform.

Anyways you can read all about SoapUI on their website. Also, there is a free open source version for download at sourceforge. Enjoy!

Focusing on application configurability and data portability

Tuesday, November 2nd, 2010

The past half year or so of developing for a company within the boundaries of a large application that spans multiple teams and multiple languages was quite a departure from my previous few years of experience freelancing. While freelancing I happily kept within the confines of the Adobe products, and probably 95% of the time within Coldfusion. Sure I would use Javascript, HTML, and CSS, but my applications were built with Coldfusion and Coldfusion alone for the dynamic portion.

As a freelancer I built code with Coldfusion knowing it could be executed by Coldfusion. Now I have to build code that is capable of transcending development languages, as well as performing optimally in the transition. While not all code moves between the languages we work with, I have to assume that it could at some point.

Applications should be configurable to some point, and when I performed Coldfusion centric development I most likely would have built my configuration in CF. This isn’t bad if your application utilizes CF and CF alone. In fact, it is certainly the best route for performance. However, as I now know, we don’t always get to develop CF centric applications. So the question arises – how can I build a configuration and data objects that can be passed to most any language and still work?

I began to, and still primarily, use XML to build configuration settings for an application. XML is a well defined and portable format that can cross most any boundary you want it to. XML can also have transformation objects (XSLT) and schema validation (XSD) applied to it for further control. It allows the configuration options to be externalized from the core components of the application. This means that Coldfusion, .net, Java, etc. can tap into that configuration for their own use. It also means that an application does not necessarily need to be regression tested in the case that data or configuration is manipulated.

Beyond configurability, we sometimes need to maintain a log of complex data that can be read across systems. For this purpose I’ve found JSON to be most useful. It’s light-weight, super portable, and is more than capable of handling objects as character strings. Here an application built with Java can log complex objects as JSON strings. A customer-facing Coldfusion application could then parse through the logs evaluating the JSON string objects and displaying appropriately.

Lastly, using JSON or XML allows complex data to be stored in a language that is more clear than the dynamic languages. For example, I probably couldn’t just jump right into a .net object and start parsing through it and utilizing the data the same way a .net developer probably couldn’t jump into a Coldfusion object and do the same. However, it is highly likely that both the CF and .net developers both understand XML, and maybe a little less likely JSON. This means that if the object structure or data needs to change the Java, .net, or Coldfusion developer can easily make the necessary changes to the externalized XML file and assume that the processing language will be capable of handling the change.

So, just some thoughts on architecting an application in a cross-language environment, while also possibly adding externalized application configurability that certainly reduces core functionality regression testing when changes need to be made.

Quick XML formatting with CF Builder

Sunday, October 17th, 2010

Pretty much every server-side language I’ve worked with has written XML to a file as compressed text. This is of course intentional in that any whitespace is indeed space and through the eyes of a program doesn’t matter. However, through the eyes of a human it does matter because large chunks of compressed xml is rather unreadable.

In the past I’ve always used Notepad++ to quickly format XML. However, this has always required opening the xml file in Notepad++ and formatting there. However, I just found in CF Builder the same feature. To use this you can either right-click anywhere in the editor containing the xml to be formatted and choose ‘Format’, or you can use the keyboard default shortcut “Shift-Command-F” on a mac or “Shift-Ctrl-F” on windows.

While I would recommend maintaining its compressed format in the file, this is a great feature for quickly making compressed XML readable.

Using an XPath wildcard

Tuesday, September 28th, 2010

In the case that you need to use XPath to retrieve an XML node, but are missing some piece of information you can use the ‘*’ as a wildcard in the XPath expression. Let’s take for example an application where a request for a certain type of house can be made and a set of XML representing that house and its details is returned. So let’s say the application requests a ‘Ranch House’. The XML returned looks like:

<House>
	<RanchHouse>
		<Floors>1</Floors>
		<Acres>8</Acres>
		<Basement>true</Basement>
	</RanchHouse>
</House>

And if we request a ‘Georgian House’ we would get:

<House>
	<GeorgianHouse>
		<Floors>3</Floors>
		<Acres>3</Acres>
		<Basement>false</Basement>
	</GeorgianHouse>
</House>

Notice that the child node of ‘House’ is different in both cases. While this may not be ideal XML it is valid and may be encountered. So we encounter this and we want to write a single XPath expression that will retrieve the number of floors for any house that is returned to us. In the expression where the the child node of ‘House’ is referenced we can use a wildcard to essentially bypass it and access its child nodes. If using the Coldfusion xmlSearch() function, our expression would look like:

<cfset variables.floors = xmlSearch(variables.myXmlObject, "/:House/*/:Floors") />

Use of the wildcard can go much further than this, but I do love how simple it is to skip over an xml node if its an unknown.