Avatar of Dan Schimo
Dan SchimoFlag for United States of America

asked on 

Coldfusion Create the Structure of Arrays with a Distinct suggestions Words

Hello Experts!

During one of my request for help , I have asked for a logic to convert an xml to Struct of arrays and it was very helpful ...

Related Question

Now we need an update the logic to contain ONLY DISTINCT values in the ARRAY
Please help ...


<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>

<cfset terms = xmlSearch(xmlfile, "/suggestions/term")>					
				
					<cfset results  = structNew()>
          <cfloop array="#terms#" index="term">
            <cfset zeroLev = xmlSearch(term, "*[@levenschtein-dist='0']")>
            <cfif ArrayLen(zeroLev) EQ 0 >
                <cfset key = term.XmlAttributes.original >
                <cfset results[key] = []>
                <cfloop array="#term.xmlChildren#" index="child">
                      <cfset arrayAppend(results[key], child.xmlText)>
                </cfloop>
            </cfif>
          </cfloop>

Open in new window

Create-Struct-array-from-XML.jpg
ColdFusion LanguageRegular ExpressionsXML

Avatar of undefined
Last Comment
_agx_
Avatar of _agx_
_agx_
Flag of United States of America image

CF8 or CF9? Also is it important to maintain the order of the array?
Avatar of Dan Schimo
Dan Schimo
Flag of United States of America image

ASKER

Cf8
Avatar of Dan Schimo
Dan Schimo
Flag of United States of America image

ASKER

Cf8 , yes order of the array is important as I am assigning the 1st word in the array as an suggestion
ASKER CERTIFIED SOLUTION
Avatar of _agx_
_agx_
Flag of United States of America image

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
Avatar of _agx_
_agx_
Flag of United States of America image

> CF has arrayFind.    But in CF8 you have to do it the long way.

Correction:  CF9 has arrayFind ...
Avatar of Dan Schimo
Dan Schimo
Flag of United States of America image

ASKER

Works Like a Charm as usual , Could you please shed some light on the chr(7) used in the Code . If you have got some Time....

--Thanks
-Dan.S
Avatar of _agx_
_agx_
Flag of United States of America image

Sure.  With list functions you must pick a delimiter that doesn't appear within the data or you get the wrong results. chr(7) is the non-printable bell character. It's very unlikely it'll appear in your data.  So it makes a pretty safe delimiter.
XML
XML

Extensible Markup Language (XML) refers to the encoding of documents such that they can be read by both machines and humans. XML documents use tags to show the beginning and end of a set of data. XML is used extensively on websites to show volumes of data, and is the default for a number of office productivity suites. This topic includes discussions of XML-related technologies, such as XQuery (the XML Query language), XPath (the XML Path language), XSLT (eXtensible Stylesheet Language Transformations), XLink (the XML Linking language) and XPointer (the XML Pointer language).

22K
Questions
--
Followers
--
Top Experts
Get a personalized solution from industry experts
Ask the experts
Read over 600 more reviews

TRUSTED BY

IBM logoIntel logoMicrosoft logoUbisoft logoSAP logo
Qualcomm logoCitrix Systems logoWorkday logoErnst & Young logo
High performer badgeUsers love us badge
LinkedIn logoFacebook logoX logoInstagram logoTikTok logoYouTube logo