[Looking for Charlie's main web site?]

Struggling with using the XML features of CFML? Here's where to learn more

Are you struggling with using the XML features in CFML? Or do you help people who are?

It's not something most people use often, and there is far more to the feature set than meets the eye. If you don't use the right resources to help you, you could waste time trying to piece together a solution using only scant examples you may find.

In this entry, I'll point to several resources you should consider to help get you quickly up to speed in using--and appreciating--the power of the XML features in CFML.

Even if you don't need them today, you (or someone you know) may need them some day, so keep this in mind. (Or if you find this page doing a google search some years down the road, drop a note to let me know if it helped then!)

Background

I just offered this info on a mailing list, but thought I'd repeat it here for readers and so that more people might find it more easily when searching.

Every once in a while someone will learn about, or need, or struggle with the XML features within CFML, which were introduced in ColdFusion MX (6). Sadly, many never notice them, or rarely use them so when folks struggle, there may not be too many people who can step up to help.

Often, people find only scant examples written by others and figure they have no choice but to try to piece together a solution, and they go through fits and starts, sometimes doing (or reading someone else doing) things in a more complicated way than is needed.

CFML's XML support is powerful, if you know where to look

The thing is, there are far more capabilities in ColdFusion's XML handling than may be obvious, even from many examples.

First, see the CFML docs--but not the CFML reference

So note first that there is significant documentation in the CFML Developer's Guide (NOT the CFML Reference). I make that distinction often, because some people seem only ever to notice the reference manual.

As is often the case, and especially for this topic, some features aren't reflected solely by specific tags or functions, but instead in ways to refer to objects as structures and arrays. The Developer's guide also is more of a user guide, walking you through "how" things work and why, rather than just showing syntax.

For CF8, that manual is here: CF 8 Developer's Guide

and the XML chapter is: Using XML and WDDX

For CF9, the manual is here: Developing Adobe ColdFusion 9 Applications

and the XML chapter (by the same name as before): Using XML and WDDX

Another great resource: Nate Weiss's mini book

While those may seem definitive, there was also an awesome extended article (about 30 pages, so more a mini book) written by Nate Weiss written back in 2002 on the then-new XML features of CFMX (6). It still is the best intro to the topic I've ever seen and one I still often recommend.

Sadly, it's gotten harder and harder to find online anymore. It used to be offered on the Adobe site, but the link no longer works. Fortunately, it's still available via the good 'ol "wayback machine". This link just worked for me.

But I've also now just gone and posted it my site instead, so that folks might find it more easily in the future:

Utilizing XML and XSLT in ColdFusion MX, by Nate Weiss (2002)

Final Resource: The CFWACK chapters

Finally, there are also chapters on XML processing in the Web Application Construction Kit books, for those who may have them.

See Chapters 45 and 46 in the second volume of the CF8 books, and chapters 41 and 42 in the second volume of the CF 9 books. (I was responsible for updating those chapters in the CF8 and 9 editions of the books, but they were written originally by Adam Churvis).

There may well be other great resources to commend, but these are are more than enough to get most people a lot further in their appreciation and understanding of using XML within CFML. (Still, see a couple of "related entries" as linked to right at the bottom of this entry.)

Hope all that helps someone.

Learning resource for beginning web developers

If you know anyone needing to learn the fundamentals of web application development--not CFML, but things like HTML, CSS, Javascript, and so on--here's an interesting resource: Beginner Developer Center, Tier 1

Yes, it's a MS resource: don't let that keep you away

Now, some will see this is from Microsoft and flinch, but don't let that scare you away. It's a set of introductory resources that could help any beginning web developer, and while the first 2 and last 2 of the 14 sections are MS-specific, the rest are not.

And besides the web-oriented topics above (HTML, CSS, Javascript, and more), there are also sections introducing basic programming concepts like problem solving, processing and storing data, even introducing OO (again, with no reference to C# or anything .NET), and more.

For each of the 14 topics, there is both an article-level discussion and either an audio or video version.

Yes, it's in a resource center about VWD. Don't let that scare you away, either

I'll note that beyond being "from MS", it's also indeed specifically part of a resource center for their Visual Web Developer IDE. Again, most of the content offered in this beginner resource is not really specific to that editor or to .NET.

And frankly, I wouldn't hold it against a CF developer to consider using the editor. Hey, it's free, and consider also that sometimes you may have to do some editing on a server with nothing but Notepad available. Perhaps you're not a fan of Eclipse, don't have an available license for DW/HS, and you want more than just Notepad. (Yes, I do also know about the many other available free (and some commercial) editor alternatives. I list them in my CF411 site category of Editors/IDEs.)

(And if you're ever stuck in a situation where you're unwilling or not allowed to install any new editor on your server, just last week I wrote about a tip for using Notepad if you ever find that you can't use the Goto Line feature.)

Anyway, the point is I'm not making a pitch here for VWD nor any statement against CFE. Let's not go there. :-) Indeed, to any who may want to take the chance to comment here in scorn or to deride the VWD editor or MS, or to point out some other editor alternative, let's not go there, either.

The point of this entry is the free learning resources for beginning web developers that I found on the MS site. I hope it may help some people.

CFFundamentals: Mimicking a form submission using CFHTTP

While developers who've used CFML for a long time will regard some topics as old hat, we have to remember that there are folks who either have come along recently or simply never used some feature. This is one of those topics, and since I answered it on a list, I offer it here.

I'd like to start doing that more often (reformatting some answer I give on some list, so that others may learn from it.) As in this case, I'll refer to such as CFFundamentals and create a category for them so that interested readers may find them more readily.

The problem

Someone wrote wanting to mimic (in CFML code) the submission of some data to a form that they saw happening within an Airborne Trackship (http://track.dhl-usa.com/TrackEmail.asp) page.

They saw that the form submitting to that allowed one to enter an email address and some tracking numbers to have a status email sent back to that address. Using "view source" in the browser, they observed that the form actually called a Javascript form which submitted the form to TrackEmail.asp?nav=TrackByEmail. Since this was on a page at http://track.dhl-usa.com/, they realized they'd need to submit to http://track.dhl-usa.com/TrackEmail.asp?nav=TrackByEmail.

They also noticed that the form had two input fields, txtTracknbrs and txtEmailAddress, so they tried to put together a CFHTTP request that tried to submit to the form using this URL:

http://track.dhl-usa.com/TrackEmail.asp?nav=TrackByEmail&txtTracknbrs=nnnnnnnnn&txtEmailAddress=someemail@address.com

It didn't work. They asked if anyone knew why.

My Response: He was close, but needed to understand a couple of points

Here's what I wrote:

I think your problem is in presuming that the Javascript method builds a request that looks like the one you tried in CFHTTP. I just reviewed the page, and I see that it's a form, with a METHOD=POST, and so your CFHTTP needs to send its info in the way a form post would. And that's NOT by passing the variables on the URL as you have. (One may argue that they can write CFML apps that accept either FORM or URL variables, but the page being called is an ASP page, so we can't make that presumption.)

With that, I changed your CFHTTP to the following and it worked (you should be getting an email soon, as it told me the request was accepted). Try it yourself:

<cfhttp url="http://track.dhl-usa.com/TrackEmail.asp" method="POST">
   <cfhttpparam type="URL" name="nav" value="TrackByEmail">
   <cfhttpparam type="FORMFIELD" name="txtTrackNbrs"
value="nnnnnnn">

   <cfhttpparam type="FORMFIELD" name="txtEmailAddress"
value="someemail@address.com">

</cfhttp>

<cfoutput>
#cfhttp.filecontent#
</cfoutput>

Note that it uses a TYPE="URL" for the nav query string value (as that WAS passed on the URL), but uses TYPE="FormField" for the form fields, since those are passed as form fields. You were right in getting the exact names of the form fields as used in the form fields of the form. That's critical as well.

I'll point out as well that when trying to mimic such forms in CFHTTP, it's also sometimes critical to send along any hidden form fields. There were two on that form, but I left them off and it seems to work. IF you found you needed to add them, just add them as more TYPE="FormField" values.

I should note as well that sometimes when trying to simulate a form submission, you will also need to send along any cookie values that might be being sent by your browser to the server. Those aren't shown in the form. You could use browser/server proxy tools (like the free Fiddler or Firebug tools) to detect what's being sent along.

Hope that may help other readers.

I'll add in this blog entry that regarding that last point, about using HTTP proxies to study the browser/server communication, I wrote about those previously in:

Alternatives HTTP debugging proxies, for debugging

BlogCFC was created by Raymond Camden. This blog is running version 5.005.

Managed Hosting Services provided by
Managed Dedicated Hosting