I figured it out.  (Well - I think I did)

I'm still worried that things could hit the fan if the document is broke...
but then again if the document is broke then serves me right, eh?  ;^)

I've appended the function and a sample block of code.  Basically you throw
it a block of code and it extracts all of the "<dpDoc>" tags it finds and
returns an array of structs where each one contains the information from the
tags.

Internally the function extracts a tag then uses the DOM functions to rip
out the data.

Anybody see any problems?  I'm worried that things are going to flake out
somehow - I'm going to do more testing, but are there any blatantly obvious
holes that I'm too blind to see?

Thanks, 

Jim Davis

Here's the function:

<cffunction     name="extractDPDocs"
                        hint="Extracts all dpDoc tags from a block of code
and returns a structure of the tag information found."
                        returntype="array"
                        access="public"
                        output="Yes">
                <!--- Input Arguments --->
        <cfargument name="CurSourceCode" type="string" required="Yes"
                                hint="The block of code to be parsed." />
                <!--- Set Local Scope --->
        <cfset var local = StructNew() />

                <!--- Set the container --->
        <cfset local.DPDocs = ArrayNew(1) />
                <!--- Set the tag name (to prevent false hits for the tag
--->
        <cfset local.DPDocTagName = "dpDoc" />

                <!--- Find the Information --->
        <cfset local.CurFindPos = 0 />
        <cfloop condition="true">
                <cfset local.DPDocsPos =
ReFindNoCase("<#local.DPDocTagName#.*?(/>|>.*?</#local.DPDocTagName#>)",
arguments.CurSourceCode, local.CurFindPos, "true") />
                <cfif local.DPDocsPos.Pos[1]>
                                <!--- Get the Element and turn it into a DOM
object --->
                        <cfset local.CurDPDocSource =
Mid(arguments.CurSourceCode, local.DPDocsPos.Pos[1], local.DPDocsPos.Len[1])
/>
                        <cfset local.CurDPDocSource =
REReplaceNoCase(local.CurDPDocSource,
"(<#local.DPDocTagName#.*?>)(.*?)(</#local.DPDocTagName#>)",
"\1<![CDATA[\2]]>\3") />
                        <cfset local.CurDPDocXML =
XMLParse(local.CurDPDocSource) />
                                <!--- Create the Container --->
                        <cfset local.CurDPDoc = StructNew() />
                                <!--- Get all the Attrbiutes --->
                        <cfloop
collection="#local.CurDPDocXML.XMLRoot.XmlAttributes#"
item="local.CurAttrib">
                                <cfset local.CurDPDoc[local.CurAttrib] =
local.CurDPDocXML.XMLRoot.XmlAttributes[local.CurAttrib] />
                        </cfloop>
                                <!--- Extract Content, if any --->
                        <cfif Trim(local.CurDPDocXML.XMLRoot.XMLText) NEQ
"">
                                <cfset local.CurDPDoc["Content"] =
local.CurDPDocXML.XMLRoot.XMLText />
                        </cfif>
                                <!--- Add the dpDoc struct to the array --->
                        <cfset ArrayAppend(local.DPDocs,
Duplicate(local.CurDPDoc)) />
                                <!--- Update the outer find position --->
                        <cfset local.CurFindPos = local.DPDocsPos.Pos[1] +
local.DPDocsPos.Len[1] />
                <cfelse>
                        <cfbreak />
                </cfif>
        </cfloop>

                <!--- Return --->
        <cfreturn local.dpDocs />

</cffunction>

Here's an example of the tags this function is designed to parse:


<dpDoc type="Information" name="Author" description="Jim Davis
([EMAIL PROTECTED])" />
<dpDoc type="Information" name="Version" description="0.1" />
<dpDoc type="Information" name="CreateDate" description="2004-02-03" />
<dpDoc type="Information" name="Overview">
        <p>cfc_DepressedPress.DP_Component is the root component which all
other DP CFCs ultimately extend.  It provides many foundation-level features
and properties.</p>
</dpDoc>
<dpDoc type="Revision" name="" date="2005-03-18" description="Initial Beta
release." />
<dpDoc type="Revision" name="" date="2005-03-31" description="Initial public
Beta release." />
<dpDoc type="Exception" name="Component.setProp.CannotSetPrivateProp"
description="The property requested is private to the CFC instance and
cannot be set." />
<dpDoc type="Exception" name="Component.setProp.CannotSetStaticProp"
description="The property requested is defined as static and cannot be set."
/>





~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
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:199474
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=89.70.4
Donations & Support: http://www.houseoffusion.com/tiny.cfm/54

Reply via email to