I need to iterate through all the attributes (regardless of name) in the sample XML in this post and create a 2D "Array of Arrays" using JQuery.
I am using Microsoft's CAML query language to return attributes from a SharePoint list. It is returned as XML which is loaded into an object. Here is the XML being returned:
<?xml version="1.0"?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"><soap:Body><GetListItemsResponse xmlns="http://schemas.microsoft.com/sharepoint/soap/"><GetListItemsResult><listitems xmlns:s="uuid:BDC6E3F0-6DA3-11d1-A2A3-00AA00C14882" xmlns:dt="uuid:C2F41010-65B3-11d1-A29F-00AA00C14882" xmlns:rs="urn:schemas-microsoft-com:rowset" xmlns:z="#RowsetSchema">
<rs:data ItemCount="3">
<z:row ows_Attachments="0" ows_LinkTitle="Apple" ows_Color="Red" ows_Quantity="3.00000000000000" ows_Quantity2="5.00000000000000" ows_MetaInfo="1;#" ows__ModerationStatus="0" ows__Level="1" ows_Title="Apple" ows_ID="1" ows_UniqueId="1;#{FEDE3004-A0F4-421F-A76B-5BD51003B11C}" ows_owshiddenversion="2" ows_FSObjType="1;#0" ows_Created_x0020_Date="1;#2012-08-01 19:24:08" ows_Created="2012-08-01 19:24:08" ows_FileLeafRef="1;#1_.000" ows_PermMask="0x7fffffffffffffff" ows_Modified="2012-08-05 13:59:06" ows_FileRef="1;#Sandbox/bitest/Lists/Produce/1_.000"/>
<z:row ows_Attachments="0" ows_LinkTitle="Orange" ows_Color="Orange" ows_Quantity="5.00000000000000" ows_Quantity2="3.00000000000000" ows_MetaInfo="2;#" ows__ModerationStatus="0" ows__Level="1" ows_Title="Orange" ows_ID="2" ows_UniqueId="2;#{1E40887F-87BF-4029-93A3-A1096DF1D1A7}" ows_owshiddenversion="2" ows_FSObjType="2;#0" ows_Created_x0020_Date="2;#2012-08-01 19:24:42" ows_Created="2012-08-01 19:24:42" ows_FileLeafRef="2;#2_.000" ows_PermMask="0x7fffffffffffffff" ows_Modified="2012-08-05 13:59:08" ows_FileRef="2;#Sandbox/bitest/Lists/Produce/2_.000"/>
<z:row ows_Attachments="0" ows_LinkTitle="Corn" ows_Color="Yellow" ows_Quantity="9.00000000000000" ows_Quantity2="19.0000000000000" ows_MetaInfo="3;#" ows__ModerationStatus="0" ows__Level="1" ows_Title="Corn" ows_ID="3" ows_UniqueId="3;#{3873272A-61AA-49C0-B5D2-A228388ADE27}" ows_owshiddenversion="5" ows_FSObjType="3;#0" ows_Created_x0020_Date="3;#2012-08-01 19:24:57" ows_Created="2012-08-01 19:24:57" ows_FileLeafRef="3;#3_.000" ows_PermMask="0x7fffffffffffffff" ows_Modified="2012-08-08 13:58:38" ows_FileRef="3;#Sandbox/bitest/Lists/Produce/3_.000"/>
</rs:data>
</listitems></GetListItemsResult></GetListItemsResponse></soap:Body></soap:Envelope>
This xml appears to be "poorly formed" and so I am having trouble iterating through its attributes for use in a 2D array. There was another post here on StackOverflow that gave me some hope. It seems that because the XML is not well formed, it isn't working.
If there were some better way to work with this data that would allow me to load all of these attributes into an array of arrays (one array for each child node) I would love to hear about it. I'm pretty green to this and I am hoping to find something simple that will work with a variety of CAML queries in the future.
------------------------------------- Edit & New Info--------------------------------
Let me add some info to this question before posting a new one.
I've somewhat given up on creating a 2D array dynamically from all the listed attributes; myself and another have not been able to get it working. It appears that I will simply have to create a custom array each time.
My new, related question: Let's say I want to get all the "Quantity2" entries from this SOAP envelope.
What is the best way to iterate through each row entry using JavaScript / JQuery and return one value for each row? I can give the current code sample I am using; it works but I am afraid that it might get confused by data values in the XML:
$(xData.responseXML).find("z\\:row").each(function() {
quantityOneArray[i] = parseFloat($(this).attr("ows_Quantity"));
quantityTwoArray[i] = parseFloat($(this).attr("ows_Quantity2"));
i++
});
I'd prefer to use DOM elements such as this example (which isn't valid):
for each $(this).childnode(function(){
Any thoughts would be appreciated!