jonese wrote:
> No we want to remove line breaks, carriage returns spaces etc. and then save
> it in our DB as a text data.
I have something for that.
Jochem
<!------------------------------------------------------------------------------
Copyright (c) 2007, Jochem van Dieten
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are
met:
* Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
------------------------------------------------------------------------------->
<cffunction access="public" name="trimXML" output="false"
hint="Recursively walk through an XML object and trim all whitespace out
of XMLtext">
<cfargument name="old" type="any" required="yes">
<cfargument name="xmlObj" type="any" required="no">
<cfset var new = 0>
<cfset var structList = "">
<cfset var xmlList = "">
<cfset var i = 0>
<cfif IsArray(old)>
<cfset new=ArrayNew(1)>
<cfloop from="1" to="#ArrayLen(old)#" index="i">
<cfset new[i] = trimXML(old[i])>
</cfloop>
<cfreturn new>
</cfif>
<cfif IsStruct(old)>
<cfset new=structNew()>
<cfset structList = StructKeyList(old)>
<cfloop list="#structList#" index="key">
<cfset new[key] = trimXML(old[key])>
</cfloop>
<cfreturn new>
</cfif>
<cfif IsXMLDoc(old)>
<cfset new=XmlNew()>
<cfset xmlList = StructKeyList(old)>
<cfloop list="#xmlList#" index="elem">
<cfset new[elem] = trimXML(old[elem], new)>
</cfloop>
<cfreturn new>
</cfif>
<cfif IsXmlElem(old)>
<cfset new=XmlElemNew(arguments.xmlObj,arguments.old.XMLName)>
<cfif Len(Trim(arguments.old.XMLText))>
<!--- Only create new XMLText when there is something left after
trimming --->
<cfset new.XMLText = arguments.old.XMLText>
</cfif>
<cfif NOT StructIsEmpty(old.XMLAttributes)>
<cfset new.XMLAttributes = Duplicate(old.XMLAttributes)>
</cfif>
<cfset structList = StructKeyList(old)>
<cfloop from="1" to="#ListLen(structList)#" index="i">
<cfset new.XmlChildren[i] =
TrimXML(old.XmlChildren[i],arguments.xmlObj)>
</cfloop>
<cfreturn new>
</cfif>
<cfif IsSimpleValue(old)>
<cfreturn old>
</cfif>
</cffunction>
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
Get involved in the latest ColdFusion discussions, product
development sharing, and articles on the Adobe Labs wiki.
http://labs/adobe.com/wiki/index.php/ColdFusion_8
Archive:
http://www.houseoffusion.com/groups/CF-Talk/message.cfm/messageid:290148
Subscription: http://www.houseoffusion.com/groups/CF-Talk/subscribe.cfm
Unsubscribe:
http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=11502.10531.4