我有一个 Tab 分隔文件,我必须将其转换为带有相关子节点的 xml。该文件看起来像这样 -
Miscellaneous
Ceremonial
Test1
Test2
Test3
Sport
Athletics
Basketball
Biathlon
Boxing
Canoeing
Clay Pigeon Shooting
Climbing
Cricket
Cycling
Diving
Football
Football
Freefall
Gliding
Hill Walking
Hockey
Martial Arts
Karate
Judo
Jujitsu
Modern Pentathlon
Mountaineering
Orienteering
Parachuting
Paragliding
Parascending
Polo
Rugby
Rugby League
Rugby Union
Soccer
我被困在节点的第三级,即武术。
这是我编写的代码,可以正常工作到第二级。
谁能告诉我要解决什么问题才能使它在第 3 级和更多级别上正常工作-
<cfif structKeyExists(form, "xlsfile") and len(form.xlsfile)>
<!--- Destination outside of web root --->
<cfset dest = getTempDirectory() />
<cffile action="upload" destination="#dest#" filefield="xlsfile" result="upload" nameconflict="makeunique">
<cfset theFileUploaded = upload.serverDirectory & "/" & upload.serverFile />
<cffile action="read" file="#theFileUploaded#" variable="theFile">
<cfset CrLf = chr(10) & chr(13) />
<cfset counter = 0 />
<cfset dataStr = structNew()>
<cfset isRoot = false>
<cfset tabCount = 0>
<cfset counter = 1>
<cfset childCounter = 1>
<cfset previousResult = 1>
<cfloop list="#theFile#" index="run" delimiters="#CrLf#">
<!--- The test value. --->
<cfset strTest = #Rtrim(run)# />
<!--- The instance counter. --->
<cfset intCount = 0 />
<!--- Get the initial position. --->
<cfset intPosition = Find( chr(9), strTest, 0 ) />
<!--- Keep searching till no more instances are found. --->
<cfloop condition="intPosition">
<!--- Increment instance counter. --->
<cfset intCount = (intCount + 1) />
<!--- Get the next position. --->
<cfset intPosition = Find(chr(9), strTest, (intPosition + Len( chr(9) ))) />
</cfloop>
<!--- Output the number of target instances.
<cfoutput>
--- #intCount# --- <br/>
</cfoutput> --->
<cfset childNode = "Child" & counter>
<cfdump var="#intCount-tabCount#">
<!--- Root --->
<cfif intCount eq 0>
<cfset dataStr.root = strTest>
<cfset tabCount = intCount>
<!--- Child at level 1 --->
<cfelseif tabCount eq 0 >
<cfset tabCount = intCount>
<cfset dataStr[childNode] = StructNew()>
<cfset dataStr[childNode].root = strTest>
<!--- Child at sub levels --->
<cfelseif ((intCount-tabCount) eq 0) or ((intCount-tabCount) eq 1)>
<cfif previousResult eq 0 and intCount-tabCount eq 1>
<cfdump var="#strTest#">
</cfif>
<cfset tabCount = intCount>
<cfset tabCount = intCount>
<cfset subChildNode = "Child" & childCounter>
<cfset dataStr[childNode][subChildNode] = strTest>
<cfset childCounter = childCounter+1>
<cfset previousResult = intCount-tabCount>
<cfelseif previousResult eq 0>
<cfset counter = counter+1>
<cfset childNode = "Child" & counter>
<cfset childCounter = 1>
<cfset tabCount = intCount>
<cfset dataStr[childNode] = StructNew()>
<cfset dataStr[childNode].root = strTest>
<cfelse>
<cfset counter = counter+1>
<cfset childNode = "Child" & counter>
<cfset childCounter = 1>
<cfset tabCount = intCount>
<cfset dataStr[childNode] = StructNew()>
<cfset dataStr[childNode].root = strTest>
</cfif>
</cfloop>
<cfdump var="#dataStr#">