탭 분리 파일이 있는데 관련 하위 노드가있는 XML로 변환해야합니다. 파일은 다음과 같습니다. -TSV에서 Coldfusion을 사용하는 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 레벨까지 작동합니다.
<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#">
정확히 무엇이 문제입니까? – Yisroel