-1

I have defined the xml as below with all information in it.

<application>
    <name>CRUD Generator</name>
    <author>User 1</author>
    <version>Beta</version>
    <description>Generate ColdFusion Components based on Database Tables</description>
    <menucontributions >
        <contribution target="rdsview" >
            <menu name="CFC Generator">
                <action name="Create CFC" handlerid="startCRUD" showResponse="no">
                    <input name="location" default="paths" label="Enter destination" tooltip="Location where generated CFCs will be stored" type="projectdir" required="true"/>
                    <input name="generateService" label="Generate Service?" tooltip="Generate service to be consumed" type="boolean" checked="true"/>
                    <input name="scriptbased" label= "Script CFC?" type="boolean" />
                </action>
            </menu>
        </contribution>
    </menucontributions>
    <!-- Define Handlers-->
    <handlers>
        <handler id="startCRUD" type="CFM" filename="cfcGen.cfm" />
    </handlers>
    <rdsview>
        <database name="dbo.AcademicDbo">
            <table name="abc">
                <fields>
                    <field name="id" type="int" length="" nullallowed="NO" primarykey="id"/>
                    <field name="CoreCode" type="varchar" length="50" nullallowed="NO" primarykey="id"/>
                    <field name="CoreDescription" type="varchar" length="250" nullallowed="NO" primarykey="id"/>
                    <field name="SubCriteriaID" type="int" length="" nullallowed="NO" primarykey="id"/>
                    <field name="modifiedby" type="int" length="" nullallowed="YES" primarykey="id"/>
                    <field name="insertby" type="int" length="" nullallowed="YES" primarykey="id"/>
                    <field name="modifieddate" type="datetime" length="" nullallowed="NO" primarykey="id"/>
                    <field name="insertdate" type="datetime" length="" nullallowed="NO" primarykey="id"/>
                    <field name="iLastActionBy" type="int" length="" nullallowed="YES" primarykey="id"/>
                    <field name="dLastActionDate" type="datetime" length="" nullallowed="YES" primarykey="id"/>
                    <field name="iLastActionBranch" type="int" length="" nullallowed="YES" primarykey="id"/>
                    
                </fields>
            </table>
        </database>
    </rdsview>
</application>

now i have the cfc but i am having some trouble finding the xml and create a working code so my components can find its value but it is not working, i am definately missing some pieces here, my xml knowlledge is not good so having hard time doing it, i already tried 3 hours but none came out, now i seek guidance

<cffunction name="parseIDEEventInfo" returntype="struct" access="public">
    <cfargument name="xml" type="string" required="true" />
    <cfset extxml= xmlParse(ARGUMENTS.xml)>
    
    <cfset extsys = {}>
    <cfset dsarr=ArrayNew(1)>
    <cfset extxmlinput = xmlSearch(extxml, "/event/user/input")>
    <cfset extxmltable ="">
    <!--<cfset extsys.input = {}>-->
    <cfloop index="i" from="1" to="#arrayLen(extxmlinput)#" >
        <cfset StructInsert(extsys.input,"#extxmlinput[i].xmlAttributes.name#","#extxmlinput[i].xmlAttributes.value#")>
    </cfloop>
    
    <cfdump var="#extxml#">
    <cfset dsarr=xmlSearch(extxml, "/rdsview/database")>
    <cfdump var="#dsarr#">
    <cfset extsys.input.datasource = dsarr[1].XMLAttributes.name>
    <cfdump var="#extxml#">
    <!---<cfset extsys.input.database = getDBType(extsys.input.datasource)>--->
    <cfset extsys.table = []>
    <cfset extxmltable = xmlSearch(extxml, "/database/table")>
    
    <cfloop index="i" from="1" to="#arrayLen(extxmltable)#">
        <cfif(find('.',extxmltable[i].xmlAttributes.name))>
            <cfset extxmltable[i].xmlAttributes.name = getToken(extxmltable[i].xmlAttributes.name, 2, '.')>
        </cfif>
        <cfset table = StructNew()>
        <cfset table.name=extxmltable[i].xmlAttributes.name>
        <cfset table.table=extxmltable[i].xmlAttributes.name>
        <cfset table.file=tCase(extxmltable[i].xmlAttributes.name)>
        <cfset table.field=[]>
        <cfif( StructkeyExists(extsys.input,"fromfb"))>
            <cfset table.field = getColumns(extxmltable[i].fields.field,"true")>
        <cfelse>
            <cfset table.field = getColumns(extxmltable[i].fields.field,"false")>
        </cfif>
        <cfset table.key = []>
        <cfset table.foreign = []>
        <cfloop index="j" from="1" to="#arrayLen(table.field)#">
            <cfif(table.field[j].isPrimaryKey)>
                <cfset arrayAppend(table.key, table.field[j])>
            </cfif>
            <cfif table.field[j].isForeignKey >
            <cfset arrayAppend(table.foreign, table.field[j])>
            </cfif>
    
        </cfloop>
        
        <cfset arrayAppend(extsys.table, table)>
    </cfloop>
        
    <!---- return success ---->
    <cfreturn extsys />     
</cffunction>

the function which i am modifying to do it and make it working order

6
  • 1
    What is not working? Are you getting errors? What exactly are you trying to get? Commented Sep 6, 2022 at 7:58
  • there are many errors but the main part where i am not understanding the part is how and why it does not search the database and the table because that is the portion where it is building its core logic Commented Sep 6, 2022 at 14:58
  • Would be informative and helpful if you mention what errors exactly you're getting. Commented Sep 6, 2022 at 15:54
  • this is the error pastebin.com/a6TMvNyv Commented Sep 6, 2022 at 18:10
  • Has @haxtbh indicated, pls include in your question the error that you are getting when you run the code. Burying it in a paste bin in a comment ain't the way to approach this. What dumps out on line 53? What does "The element at position 1 cannot be found." tell you? Also when you have a problem with a concept like "searching XML", don't give us dozens of lines of irrelevant code. Just give us enough to demonstrate the problem, and if you make it portable and runnable (eg: trycf.com/gist/27d01ecf27b4fde5a5ef38e821fd4077/…), so much the better. Commented Sep 7, 2022 at 7:18

1 Answer 1

0

You are searching for /rdsview/database in your XML document, but the top level of the doc is applicaction.

There are two relevant strategies here. First: just get yer search string correct, it would be: /applicaction/rdsview/database. This returns results from your xmlSearch.

Secondly if you just wanted the nodes matching a subhierarchy of /rdsview/database anywhere in the doc (not necessarily immediately within application) you could search for //rdsview/database.

However in this case it's the former you want to be doing, given /rdsview/database only appears in one place in the hierarchy in the first place.

I have found http://zvon.org/comp/r/tut-XPath_1.html#Pages~List_of_XPaths to be a good reference for explaining how XPath strings work.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.