Returning object from plugin

Returning object from plugin

Hey all, I'm relatively new to JQuery and Javascript but I feel like I've been banging my head against a wall all day and I could use some help.

Basically what I'm trying to do is write a plug in which connects to a sharepoint web service, traverse the results of the xml document that is returned by the web service for certain elements, and then return a collection of xml elements which I can use in another function on the page that is calling the plugin.

My code looks like this:

Main Page
   <script type="text/javascript">
       $(document).ready(function() {
       var listItems = $.sharepoint();
      for (var i = 0; i < listItems.length; i++) { 
           var row = listItems[i]; 
           var title = row.getAttribute("ows_Title");
           alert(title);
           var url = row.getAttribute("ows_URL");
                        alert(url);
        };
   });
</script>


JQuery Plugin
(function($) {
  $.fn.sharepoint = function() {
  return this.each(function() {
     var soapEnv =
              "<soapenv:Envelope xmlns:soapenv='http://schemas.xmlsoap.org/soap/envelope/'> \
                  <soapenv:Body> \
                       <GetListItems xmlns='http://schemas.microsoft.com/sharepoint/soap/'> \
                          <listName>NavBarLinks</listName> \
                          <viewFields> \
                              <ViewFields> \
                                 <FieldRef Name='Title' /> \
                                 <FieldRef Name='URL' /> \
                             </ViewFields> \
                          </viewFields> \
                      </GetListItems> \
                  </soapenv:Body> \
              </soapenv:Envelope>";

        $.ajax({
            url: "http://ewidev-srv1:8150/_vti_bin/lists.asmx",
            type: "POST",
            dataType: "xml",
            data: soapEnv,
            complete: processResult,
            contentType: "text/xml; charset=\"utf-8\""
        });

    function processResult(xData, status) {
         var rows = xData.responseXML.getElementsByTagName('z:row');
           return rows;
        }
     });
  };
})(jQuery);


I don't know if I'm allowed to use
var listItems = $.sharepoint();
when calling my jquery plugin, but how else would I accomplish this?

I really just want a collection of xml elements returned so that in my main page I can use that data to accomplish certain tasks, like create links based off that data. The idea here is that I could call this method eventually in other pages and I want to basically create a plugin full of methods that would return certain sharepoint list data.

Is there another way to accomplish what I'm trying to do here?


Thanks in advance for your help.