Dan Schimo
asked on
ColdFusion to convert a XML in the Structure of Arrays and avoiding the Node levenschtein-dist =0
My code is attached which is creating a struct of arrays as the
Related Question
I would like to Avoid the Node which has a levenschtein-dist =0.
--Dan
<cfset terms = xmlSearch(xmlfile, "/suggestions/term")>
<cfset results = structNew()>
<cfloop array="#terms#" index="term">
<cfset key = term.XmlAttributes.original >
<cfset results[key] = []>
<cfloop array="#term.xmlChildren#" index="child">
<cfif child.xmlName eq "suggestion">
<cfset arrayAppend(results[key], child.xmlText)>
</cfif>
</cfloop>
</cfloop>
Can you please post the xml document also for testing?
Check this:
<cfset terms = xmlSearch(xmlfile, "/suggestions/term/suggestion[@levenstein-dist!='0']")>
ASKER
sorry it returns empty struct
ASKER
<suggestions elapsed-time="PT0.010333S"><term original="dissorder"><suggestion levenschtein-dist="1">Disorder</suggestion><suggestion levenschtein-dist="1">disorder</suggestion><suggestion levenschtein-dist="2">Disorders</suggestion><suggestion levenschtein-dist="2">disorders</suggestion><suggestion levenschtein-dist="2">distorter</suggestion></term><term original="sleep"><suggestion levenschtein-dist="0">Sleep</suggestion><suggestion levenschtein-dist="0">sleep</suggestion><suggestion levenschtein-dist="1">asleep</suggestion><suggestion levenschtein-dist="1">seep</suggestion><suggestion levenschtein-dist="1">sleeps</suggestion></term></suggestions>
its a webservice which is called by cfhttp
the output you are seeing is the <cfdump var="#cfhttp.filecontent#"
-Dan
Show your xml data then I can check for you.
Test also the short notation:
Test also the short notation:
<cfset terms = xmlSearch(xmlfile, "//suggestion[@levenstein-dist!='0']")>
ASKER
Didn't work either, I posted the XML Data....
OK, I see that Ihave misspelled your lewenSCHtein attribute. Check that.
ASKER
Zvonko,
I corrected the misspelled levenschtein-dist="1"
and I am getting the array of structs which is not I am looking for...
I am trying to construct a Struct of Arrays from XML Please refer this was my previous questions.
where a Struct of arrays are constructed.
I would like to exclude the NODE (struct) where the any of its attributes levenschtein-dist="0"
I corrected the misspelled levenschtein-dist="1"
and I am getting the array of structs which is not I am looking for...
I am trying to construct a Struct of Arrays from XML Please refer this was my previous questions.
where a Struct of arrays are constructed.
I would like to exclude the NODE (struct) where the any of its attributes levenschtein-dist="0"
Extend this one line:
<cfif child.xmlName eq "suggestion" and child.getAttribute("levenschtein-dist") NEQ "0" >
ASKER
I put the extension and I have got a scrn shot before and after adding the code . also the thing I need to accomplish. sorry if i am unable to express my requirement...
<cfset terms = xmlSearch(xmlfile, "/suggestions/term")>
<cfset results = structNew()>
<cfloop array="#terms#" index="term">
<cfset key = term.XmlAttributes.original >
<cfset results[key] = []>
<cfloop array="#term.xmlChildren#" index="child">
<cfif child.xmlName eq "suggestion" and child.getAttribute("levenschtein-dist") NEQ "0">
<cfset arrayAppend(results[key], child.xmlText)>
</cfif>
</cfloop>
</cfloop>
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks Zvonko , that did it !