У меня есть файл, разделенный вкладками, и я должен преобразовать его в 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-м уровне узла, то есть боевых искусствах.
Вот код, который я написал и отлично работает до 2-го уровня.
Кто-нибудь, пожалуйста, скажите мне, что исправить, чтобы он работал на 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#">