If it helps, I wrote a little UDF for this...can't guarantee it'll be
100% on all of the time, I scrawled it out quickly for my own quick
use a while back.

<cffunction name="prettyXml" returnType="string" output="false">
        <cfargument name="xmlNode">
        <cfargument name="depth" default="0">

        <cfset var result = "" />

        <cfset result = repeatString(chr(9), arguments.depth) &
"<#arguments.xmlNode.xmlName#" />

        <cfloop collection="#arguments.xmlNode.xmlAttributes#" item="i">
                <cfset result = result & " 
#i#=""#arguments.xmlNode.xmlAttributes[i]#""">
        </cfloop>

        <cfif not len(arguments.xmlNode.xmlText) and not
arrayLen(arguments.xmlNode.xmlChildren)>
                <cfset result = result & " /">
        </cfif>

        <cfset result = result & ">" />
        <cfif len(trim(arguments.xmlNode.xmlText))>
                <cfset result = result & chr(10) & repeatString(chr(9),
arguments.depth + 1) & htmlEditFormat(arguments.xmlNode.xmlText) &
chr(10) />
        <cfelse>
                <cfset result = result & chr(10) />
        </cfif>

        <cfloop from="1" to="#arrayLen(arguments.xmlNode.xmlChildren)#" 
index="i">
                <cfset result = result & 
prettyXml(arguments.xmlNode.xmlChildren[i],
arguments.depth + 1) />
        </cfloop>

        <cfif len(arguments.xmlNode.xmlText) or
arrayLen(arguments.xmlNode.xmlChildren)>
                <cfset result = result & repeatString(chr(9), arguments.depth) &
"</#arguments.xmlNode.xmlName#>" & chr(10) />
        </cfif>

        <cfreturn result />
</cffunction>


On 5/24/05, Barney Boisvert <[EMAIL PROTECTED]> wrote:
> Not with CF natively.  XML (like HTML) is whitespace agnostic, so the
> XML doesnt care if it's one long line, or a nicely formatted
> (according to an arbitrary human).  You could probably write a
> formatter fairly easily, depending on the complexity of the formatting
> rules you wanted to enforce.
> 
> At it's simplest, just do replace(xmlString, ">", ">#chr(10)#",
> "all"), but that'll only give you linebreaks, you'll have to write an
> actual parser that tracks nesting depth if you want to do indentation
> and stuff.
> 
> cheers,
> barneyb
> 
> On 5/24/05, Johnny Le <[EMAIL PROTECTED]> wrote:
> > Hi,
> >
> > Is there a way to format the xml string before writing back to the file?  
> > The problem I have is when I use toString(xmlObject) to convert the xml 
> > object to string to write to a file, it becomes one long ugly string.  Is 
> > there an easy to format it with indentation and all?
> >
> > Johnny
> --
> Barney Boisvert
> [EMAIL PROTECTED]
> 360.319.6145
> http://www.barneyb.com/
> 
> Got Gmail? I have 50 invites.
> 
> 

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
Logware (www.logware.us): a new and convenient web-based time tracking 
application. Start tracking and documenting hours spent on a project or with a 
client with Logware today. Try it for free with a 15 day trial account.
http://www.houseoffusion.com/banners/view.cfm?bannerid=67

Message: http://www.houseoffusion.com/lists.cfm/link=i:4:207559
Archives: http://www.houseoffusion.com/cf_lists/threads.cfm/4
Subscription: http://www.houseoffusion.com/lists.cfm/link=s:4
Unsubscribe: 
http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=11502.10531.4
Donations & Support: http://www.houseoffusion.com/tiny.cfm/54

Reply via email to