Talk:AJAX - Return Arrays and Structs to your JavaScript with XML: Difference between revisions

Answer
(Answer)
Line 17: Line 17:
Is there a reason why this has not been used in this case ? eg would this work for AJAX ?
Is there a reason why this has not been used in this case ? eg would this work for AJAX ?
 
 
{ Published = True  }
{ Published = True  }
{ Description = ""  }
{ Description = ""  }
Function NameCasing String sName Returns XMLHandle
Function NameCasing String sName Returns XMLHandle
  Handle hoRoot hoXML hoEvent
  Handle hoRoot hoXML hoEvent
  Address aXml
  Address aXml
  // create xml document
  // create xml document
  Get Create U_cXMLDOMDocument                            to hoXML
  Get Create U_cXMLDOMDocument                            to hoXML
  Set pbValidateOnParse of hoXML                          to False
  Set pbValidateOnParse of hoXML                          to False
  Get CreateDocumentElement of hoXML "response"          to hoRoot
  Get CreateDocumentElement of hoXML "response"          to hoRoot
  Send AddElement of hoRoot "lowercase" (lowercase(sName))
  Send AddElement of hoRoot "lowercase" (lowercase(sName))
  Send AddElement of hoRoot "uppercase" (Uppercase(sName))
  Send AddElement of hoRoot "uppercase" (Uppercase(sName))
  Send AddElement of hoRoot "propercase" (Uppercase(Left(sName,1))+lowercase(Right(sName,(length(sName)-1))))
  Send AddElement of hoRoot "propercase" (Uppercase(Left(sName,1))+lowercase(Right(sName,(length(sName)-1))))
  Function_Return hoXML  // runtime will transfer and then destroy this object because of XMLHandle return type
  Function_Return hoXML  // runtime will transfer and then destroy this object because of XMLHandle return type
End_Function  // NameChanges
End_Function  // NameChanges
 
: Akennard - try typing "paXML" into the VDF Help Index (that's all I did, using VDF 14.0 Help) and you will get a page which includes the following: "<font color="red">''Note: This property allocates memory for the data and it is therefore important that the data be disposed of when you are done. This is done using the Free() function.''</font>" This is the clue to what is going on: you have an XML object (hoXML is a reference to this) which you later destroy, but calling paXML has a specific (and ''documented''!!!) side effect: "<font color="red">''This property <u>allocates</u> memory...''</font>" (which, IMO, makes it a function/method, not a property... but then I'm picky!) - and into that memory it then <u>copies</u> the XML of the object it was called on (although the documentation does not explicitly state this, it does clearly imply it), so it is independent of that object and does not disappear when you "Destroy" it, which is why you need to manually "Free()" the memory when you are done. HTH.
 
: I don't think the example you describe would work the way you want - it would return the integer object ID of the XML object you created, which I'm guessing is not your intent!  [[Image:Sad.jpg]] --[[User:Mikepeat|Mike]] 15:38, 15 January 2009 (UTC)


== I believe using JSon is a much better match. ==
== I believe using JSon is a much better match. ==