Skip to main content
Participating Frequently
November 26, 2015
Answered

Search XML with or without special characters

  • November 26, 2015
  • 1 reply
  • 332 views

Hi,

Please i need your help: I have this XML:

<nodoPrincipal >

<content linkName="" url="" linkType="multi" searchableTerms="generación, vida, familia, ">

<multiLink url="cdw/day1/iAmFrom.doc"/>

<multiLink url="cdw/day1/iAmFrom.pdf"/>

</content>

<content linkName="" url="" linkType="multi" searchableTerms="casa, cama, ropa, ">

<multiLink url="cdw/day1/influences.doc"/>

<multiLink url="cdw/day1/influences.pdf"/>

</content>

<content linkName="" url="day1/Strengths.ppt" linkType="dl" searchableTerms="teléfono, celular, computación, ">

<desc><![CDATA[Strengths Finder]]></desc>

</content>

<content linkName="" url="" linkType="multi" searchableTerms="objeto, carta, mesa, ">

<multiLink url="cdw/day1/haveDoBe.doc"/>

<multiLink url="cdw/day1/haveDoBe.pdf"/>

</content>

</nodoPrincipal>

And this function to search:

//xml loaded above

function processSearchXML(xmlData:XML, searchTerm:String):XMLList

{

  var searchData:XMLList = xmlData.*;

  //if the node has searchable terms, add it to the list

  var searchTerms:XMLList = searchData.(hasOwnProperty('@searchableTerms'));

  //A list for the results

  var searchResults:XMLList = new XMLList();

  for each(var searchItem:XML in searchTerms)

  {

  //gets the attribute searchableTerms

  var searchSplit:String = searchItem.@searchableTerms.toXMLString();

  //builds the array of " , " seperated values

  //so that I can have multiple search terms

  var searchTerms_ary:Array = searchSplit.split(", ");

  //A list for the results

  var searchResults_ary:Array = new Array();

  //trace(searchTerms_ary.length +" searchable terms in node");

  //search the array

  for each(var term:String in searchTerms_ary)

  {

  //if the record matches what I searched for, add it to the results array

  if (term == searchTerm)

  {

  //trace(term + " has met the seach craiteria");

  searchResults_ary.push(term);

  }

  }

  //trace(searchResults_ary.length +" results in node");

  //trace();

  //if anything was added to the array

  //add the branch to the xml list

  if(searchResults_ary.length != 0)

  {

  searchResults += searchItem;

  }

  }

   trace(searchResults);

  return searchResults;

}

With this function I managed find whole words, but I want to search for parts of words and search with special characters such as: teléfono   or     telé

help me plesase!!!

This topic has been closed for replies.
Correct answer kglad

use indexOf instead of checking for a match if you want to retrieve parital matches.  eg,

  if (term.indexOf(searchTerm)>-1)


instead of


  if (term == searchTerm)

1 reply

kglad
Community Expert
kgladCommunity ExpertCorrect answer
Community Expert
November 26, 2015

use indexOf instead of checking for a match if you want to retrieve parital matches.  eg,

  if (term.indexOf(searchTerm)>-1)


instead of


  if (term == searchTerm)

BenbaodanAuthor
Participating Frequently
November 26, 2015

Thank glad, sometimes escape us details so simple !!!

kglad
Community Expert
Community Expert
November 26, 2015

you're welcome.