I can't remember how this came up, but the other day I was talking to this girl about XML; it was a pretty engaging conversation, as you can probably well imagine. I was trying to explain the difference between a ColdFusion XML document object and an XML string when the question occurred to me - can you use ToString() to get a partial representation of an XML document object.
Traditionally, you can call ToString() on an entire ColdFusion XML document to get an XML string representation:
Launch code in new window » Download code as text file »
But, what about calling that on an individual XML node that is within the XML document. I gave it a go:
Launch code in new window » Download code as text file »
As you can see, we are calling ColdFusion's ToString() method on only the third girl element node in the XML document. Running this gives us the following output:
Launch code in new window » Download code as text file »
Pretty cool! Not only did it give us the string representation of the single XML node, it also gave us the XML document type.
NOTE: I modified the tabbing of the outputted string for easier reading.
Download Code Snippet ZIP File
Comments (3) | Post Comment | Ask Ben | Permalink | Other Searches | Print Page
Getting Only The Date Part Of A Date/Time Stamp in SQL Server (Revisited)
Convert jQuery XML Documentation To HTML / PDF Using ColdFusion And XSLT
Definitely did not know you could do that. Cool, and thanks for pointing it out!
Posted by Sammy Larbi on Sep 20, 2007 at 4:23 PM
No worries. Been doing a lot of XML learning lately.
Posted by Ben Nadel on Sep 20, 2007 at 4:41 PM
Great tips, thanks for it.
Posted by Jerry on Apr 21, 2008 at 3:09 AM