Ask Ben: Changing The Root Node In A ColdFusion XML Document

<!---
	Replace the first and last nodes of the document with a
	new node name. We are going to do this in two step. Start
	with the first tag.
--->
<cfset strXmlData = REReplace(
	strXmlData,
	"<\w+",
	"<masterlist",
	"one"
	) />
 
<!---
	Now, we want to replace the LAST close node in the document.
	Because we want to replace the last close node, we want the
	expression to end in the $ so that it is the end of the
	document.
--->
<cfset strXmlData = REReplace(
	strXmlData,
	"(</)\w+([^>]*>\s*)$",
	"\1masterlist\2",
	"one"
	) />
 
 
<!--- Parse and output new XML. --->
<cfdump
	var="#XmlParse( Trim( strXmlData ) )#"
	label="New XML Document"
	/>

For Cut-and-Paste