Title: Windows Live Agents: XML Normalization II
Slug: windows-live-agents-xml-normalization-ii
Date: 2008-04-02 23:04:00
Author: Kartones
Lang: en
Tags: Development, XML, Windows Live Agents
Description: XML normalization using Windows Live Agents, focusing on utilizing the MakeHash() function to remove repeated list elements efficiently.

 <p align="justify"><br>In my <a href="https://blog.kartones.net/post/windows-live-agents-xml-normalization">last WLA post</a> I talked about normalizing xmls to be able to handle complex structures. We learned how splitting the fields in multiple xmls we could do simple querys and get the wanted data. </p> <p align="justify">But what about after having this data? How can we cross it to obtain some manageable info?</p> <p align="justify">The solution I use is very simple if you know the existence of the <font face="Courier New" size="2">MakeHash()</font> function.</p> <p align="justify">This function accepts one or two parameters and (among other things), if you call it with the same list object in both parameters, it will cycle through all the list elements and remove repeated ones. For example, if we have a list called <font face="Courier New" size="2">MYLIST</font> with the values <font face="Courier New" size="2">1,1,2,3</font>, <font face="Courier New" size="2">MakeHash(MYLIST,MYLIST)</font> will return a list with the values <font face="Courier New" size="2">1,2,3</font>.</p> <p align="justify">In this example, we have two simple functions that retrieve values using simple querys:</p> <p align="justify"><font face="Courier New" size="2">GetIDsFromTable1(1)</font> returns <font face="Courier New" size="2">1,2,3</font></p> <p align="justify"><font face="Courier New" size="2">GetIDsFromTable2(1)</font> returns <font face="Courier New" size="2">1,3,4</font></p> <p align="justify">We can easily build a function that returns both results without repeating values:</p> <p><font face="Courier New" size="2">function GetIDsFromTables(REGISTERID)<br>  RESULTS = ""<br>  IDS = <b>GetIDsFromTable1</b>(REGISTERID)<br>    for value ID in IDS<br>      insert last in RESULTS ID<br>  IDS = <b>GetIDsFromTable2</b>(REGISTERID)<br>    for value ID in IDS<br>      insert last in RESULTS ID<br>  RESULTS = MakeHash(RESULTS,RESULTS)<br>  return RESULTS</font>  </p><p align="justify">So, calling <font face="Courier New" size="2">GetIDsFromTables(1)</font> will return <font face="Courier New" size="2">1,2,3,4</font>  :)</p>
