General Interface is an open source project hosted by the Dojo Foundation

GI Contributor Blog Blog from Jun 11, 2009

  2009/06/11
How to do asynchronous XML resource loading.
Last Changed by Darren Hwang, Apr 27, 2011 18:18
Labels: asynch, xml

Some of the FAQ that user have on XML resource are: Is there a build in way of doing asynchronous loading and caching of XML document? , How do I fetch xml document into the application cache asynchronously ? and How can I make sure that what I load myself will be used by GI instead loading again from the web server?

Well, quick answer is : Yes, use

myProject.getCache().getOrOpenAsync("component/file.xml")
Asynchronous Loading
  • Cache documents can be loaded asychronously with the getOrOpenAsync()_method. This method returns the corresponding document synchronously if it already exists in the cache. If the document does not exist in the cache, then it is loaded asynchronously and the method returns a placeholder document. The namespace URI of this placeholder document isCache.XSDNS_ and its root node name is "loading".
Method getOrOpenAsync(strURL, strId, objClass) Asynchronously loads an xml document and stores it in this cache.
Parameters:
  • strURL {String | jsx3.net.URI} - url (relative or absolute) the URI of the document to open.
  • strId – the id under which to store the document. If this parameter is not provided, thestrURL parameter is used as the id.
  • objClass {jsx3.lang.Class} - jsx3.xml.Document (default value) or one of its subclasses. The class with which to instantiate the new document instance.
Returns:

{jsx3.xml.Document} – the document retrieved from the cache or a placeholder document if the document is in the process of loading asynchronously.

Since:

3.5

When Cache document are loaded (or "set"), you get a event notification from Cache. The subject is your cache document name.

MYAPP.getCache().getOrOpenAsync(this.APP.resolveURI("components/list_of_states.xml"), "list_of_states");
MYAPP.getCache().subscribe("list_of_states", function() {jsx3.log("loaded"); }
Posted at 11 Jun @ 5:26 PM by Darren Hwang | 2 Comments