<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://dataflex.wiki/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=AKennard</id>
	<title>DataFlex Wiki - User contributions [en]</title>
	<link rel="self" type="application/atom+xml" href="https://dataflex.wiki/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=AKennard"/>
	<link rel="alternate" type="text/html" href="https://dataflex.wiki/index.php?title=Special:Contributions/AKennard"/>
	<updated>2026-04-30T15:16:18Z</updated>
	<subtitle>User contributions</subtitle>
	<generator>MediaWiki 1.43.8</generator>
	<entry>
		<id>https://dataflex.wiki/index.php?title=AJAX_-_Return_Arrays_and_Structs_to_your_JavaScript_with_XML&amp;diff=2256</id>
		<title>AJAX - Return Arrays and Structs to your JavaScript with XML</title>
		<link rel="alternate" type="text/html" href="https://dataflex.wiki/index.php?title=AJAX_-_Return_Arrays_and_Structs_to_your_JavaScript_with_XML&amp;diff=2256"/>
		<updated>2008-12-17T10:32:05Z</updated>

		<summary type="html">&lt;p&gt;AKennard: /* Creating the XML in the WBO */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= Functionality =&lt;br /&gt;
&lt;br /&gt;
The VDF AJAX Library provides the functionality for developers to call published methods within a WBO and receive a return value (for Functions). This is done using a Remote Method Invokation (RMI). Using  RMI&#039;s for returning a single datatype is fairly straight-forward. If you want to return a Struct, Array , or an Array of Structs you need to do some more work. Remember, you are returning these datatypes to JavaScript and there is no direct translation from a Windows Struct or Array to a JavaScript Struct or Array.&lt;br /&gt;
&lt;br /&gt;
= The Solution =&lt;br /&gt;
&lt;br /&gt;
The solution is to return the data in an XML document. XML can be formatted to return a Struct of data, and Array, or an Array of Structs.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= Calling the WBO Function from JavaScript =&lt;br /&gt;
&lt;br /&gt;
This is an example of a JavaScript function using the RMI to call a function of the webapp. It called the Function NameCasing of the oMyWBO. It passes a single argument of sName. When the Function returns, it will call the JavaScript method onNameCasing.&lt;br /&gt;
&lt;br /&gt;
 function nameCasing(sName) {&lt;br /&gt;
   var oRMI = new VdfRemoteMethodInvocation(true, &amp;quot;oMyWBO&amp;quot;, &amp;quot;get_NameCasing&amp;quot;, null, onNameCasing);&lt;br /&gt;
   oRMI.addParameter(sName);&lt;br /&gt;
   oRMI.sendCall();&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= Creating the XML in the WBO =&lt;br /&gt;
&lt;br /&gt;
1) create an XML document&amp;lt;br/&amp;gt;&lt;br /&gt;
2) add elements to the XML&amp;lt;br/&amp;gt;&lt;br /&gt;
3) get the memory address of the XML document&amp;lt;br/&amp;gt;&lt;br /&gt;
4) destroy the VDF connection to the address&amp;lt;br/&amp;gt;&lt;br /&gt;
5) return the memory address. This will return the XML document to the JavaScript&amp;lt;br/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 { Published = True  }&lt;br /&gt;
 { Description = &amp;quot;&amp;quot;  }&lt;br /&gt;
 Function NameCasing String sName Returns Address&lt;br /&gt;
   Handle hoRoot hoXML hoEvent&lt;br /&gt;
   Address aXml&lt;br /&gt;
   // create xml document&lt;br /&gt;
   Get Create U_cXMLDOMDocument                            to hoXML&lt;br /&gt;
   Set pbValidateOnParse of hoXML                          to False&lt;br /&gt;
   Get CreateDocumentElement of hoXML &amp;quot;response&amp;quot;           to hoRoot&lt;br /&gt;
   Send AddElement of hoRoot &amp;quot;lowercase&amp;quot; (lowercase(sName))&lt;br /&gt;
   Send AddElement of hoRoot &amp;quot;uppercase&amp;quot; (Uppercase(sName))&lt;br /&gt;
   Send AddElement of hoRoot &amp;quot;propercase&amp;quot; (Uppercase(Left(sName,1))+lowercase(Right(sName,(length(sName)-1))))&lt;br /&gt;
   Get paXml of hoXml to aXml&lt;br /&gt;
   Send Destroy of hoRoot&lt;br /&gt;
   Send Destroy of hoXML&lt;br /&gt;
   Function_Return aXML&lt;br /&gt;
 End_Function   // NameChanges&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
I just wanted to ask &#039;why&#039; this works ....&lt;br /&gt;
&lt;br /&gt;
    Get paXml of hoXml to aXml&lt;br /&gt;
    Send Destroy of hoRoot&lt;br /&gt;
    Send Destroy of hoXML&lt;br /&gt;
    Function_Return aXML&lt;br /&gt;
End_Function&lt;br /&gt;
&lt;br /&gt;
Is it because VDF does not ACTUALLY destroy and objects untill it gets to end_function ? because returning a handle to something you have just destroyed doesn&#039;t look quite right ? ie you are returning a handle to nothing or something that might still exist at that point ?&lt;br /&gt;
&lt;br /&gt;
VDF has a special XmlHandle return type for returning a hoXML object and the tidying up after itself&lt;br /&gt;
&lt;br /&gt;
Is there a reason why this has not been used in this case ? eg would this work for AJAX ?&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
{ Published = True  }&lt;br /&gt;
{ Description = &amp;quot;&amp;quot;  }&lt;br /&gt;
Function NameCasing String sName Returns XMLHandle&lt;br /&gt;
  Handle hoRoot hoXML hoEvent&lt;br /&gt;
  Address aXml&lt;br /&gt;
  // create xml document&lt;br /&gt;
  Get Create U_cXMLDOMDocument                            to hoXML&lt;br /&gt;
  Set pbValidateOnParse of hoXML                          to False&lt;br /&gt;
  Get CreateDocumentElement of hoXML &amp;quot;response&amp;quot;           to hoRoot&lt;br /&gt;
  Send AddElement of hoRoot &amp;quot;lowercase&amp;quot; (lowercase(sName))&lt;br /&gt;
  Send AddElement of hoRoot &amp;quot;uppercase&amp;quot; (Uppercase(sName))&lt;br /&gt;
  Send AddElement of hoRoot &amp;quot;propercase&amp;quot; (Uppercase(Left(sName,1))+lowercase(Right(sName,(length(sName)-1))))&lt;br /&gt;
  Function_Return hoXML  // runtime will transfer and then destroy this object because of XMLHandle return type&lt;br /&gt;
End_Function   // NameChanges&lt;br /&gt;
&lt;br /&gt;
= Parsing the XML in JavaScript =&lt;br /&gt;
&lt;br /&gt;
1) check to see if there were any errors&amp;lt;br/&amp;gt;&lt;br /&gt;
2) make sure we have a return value&amp;lt;br/&amp;gt;&lt;br /&gt;
3) create the XML parser object&amp;lt;br/&amp;gt;&lt;br /&gt;
4) get the values from the XML&lt;br /&gt;
&lt;br /&gt;
 function onNameCasing(oRMI) {&lt;br /&gt;
   // If no errors&lt;br /&gt;
   if (oRMI.iErrorNumber==0){&lt;br /&gt;
     if (oRMI.sReturnValue!=null){&lt;br /&gt;
       // create XML parser&lt;br /&gt;
       try { // code for IE&lt;br /&gt;
         xmlDoc=new ActiveXObject(&amp;quot;Microsoft.XMLDOM&amp;quot;);&lt;br /&gt;
         xmlDoc.async=&amp;quot;false&amp;quot;;&lt;br /&gt;
         xmlDoc.loadXML(oRMI.sReturnValue);&lt;br /&gt;
       } catch(e) { // code for Mozilla, Firefox, Opera, etc.&lt;br /&gt;
         try {&lt;br /&gt;
           parser=new DOMParser();&lt;br /&gt;
           xmlDoc=parser.parseFromString(oRMI.sReturnValue,&amp;quot;text/xml&amp;quot;);&lt;br /&gt;
         } catch(e) {&lt;br /&gt;
           alert(e.message);&lt;br /&gt;
           return;&lt;br /&gt;
         }&lt;br /&gt;
       }&lt;br /&gt;
     }&lt;br /&gt;
     if (xmlDoc!=null){&lt;br /&gt;
       var sLower=&amp;quot;&amp;quot;, sUpper=&amp;quot;&amp;quot;, sProper=&amp;quot;&amp;quot;;&lt;br /&gt;
       sLower=xmlDoc.getElementsByTagName(&amp;quot;lowercase&amp;quot;)[0].childNodes[0].nodeValue;&lt;br /&gt;
       sUpper=xmlDoc.getElementsByTagName(&amp;quot;uppercase&amp;quot;)[0].childNodes[0].nodeValue;&lt;br /&gt;
       sProper=xmlDoc.getElementsByTagName(&amp;quot;propercase&amp;quot;)[0].childNodes[0].nodeValue;&lt;br /&gt;
       //todo: do something with these values&lt;br /&gt;
     }&lt;br /&gt;
   }&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
[[Category:Web Programming]]&lt;br /&gt;
[[Category:AJAX]]&lt;/div&gt;</summary>
		<author><name>AKennard</name></author>
	</entry>
</feed>