0

I am trying to create a chart (with amCharts) from data we store in one of our internal Sharepoint lists.

These lists can thankfully be converted to a XML format via a RESTful URL query. These queries look like this:

https://sharepoint/_vti_bin/owssvr.dll?Cmd=Display&List=%7B812FC713-F916-4284-B50F-2EC3B8E80C98%7D&View=%7BAAFAA130-33B1-4A21-9E98-C25FECEF79E4%7D&XMLDATA=TRUE?Cmd=Display&List=%7B812FC713-F916-4284-B50F-2EC3B8E80C98%7D&View=%7BAAFAA130-33B1-4A21-9E98-C25FECEF79E4%7D&XMLDATA=TRUE

The resulting XML data doesn't have a standard header / mime-type / etc. though and goes like:

<xml 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'>

<s:Schema id='RowsetSchema'>
...
</s:Schema>

<rs:data>
...
</rs:data>

</xml>

Now what I need to do in order to transform and work with the data in javascript, so that I can ultimately insert it into the chart, is to be able to parse it in my web application (html / php / plain js).

Normally I'd do a xmlhttprequest() in this case, however, I have tried this already and it failed me. Seemingly it can't utilize an URL as the xml source. Unfortunately there aren't any error messages either...

Here's the function I've used (including debug alerts):

<script type="text/javascript"> 
function loadXMLDoc(XMLname)
{
alert("Function loaded");
var xmlDoc;
if (window.XMLHttpRequest)
{
alert("Chrome, getting XML");
xmlDoc=new window.XMLHttpRequest();
xmlDoc.open("GET",XMLname,false);
xmlDoc.send("");
alert("Chrome, got XML");
return xmlDoc.responseXML;
}
// IE 5 and IE 6
else if (ActiveXObject("Microsoft.XMLDOM"))
{
alert("IE, getting XML");
xmlDoc=new ActiveXObject("Microsoft.XMLDOM");
xmlDoc.async=false;
xmlDoc.load(XMLname);
alert("IE, got XML");
return xmlDoc;
}
alert("Error loading document!");
return null;
}
</script>

The function loads correctly, then correctly chooses the Chrome/Firefox path and starts requesting the data via a "GET" query.

This query doesn't ever give back a result or error message though and the

alert("Chrome, got XML");

is never reached.

Does anyone have any idea why there are no error messages or how to actually parse a XML URL with javascript?

best regards

daZza

1 Answer 1

1

I assume you are using SharePoint 2010. It is not clear why you are consuming SharePoint Foundation RPC Protocol methods to access SharePoint List data.

In addition to RPC, SharePoint 2010 supports REST, JSOM or SOAP Services.

The following example demonstrate how to read list items using SharePoint 2010 REST API:

function getListItems(webUrl,listName, success, failure) {
    var url = webUrl + "/_vti_bin/listdata.svc/" + listName;
    $.ajax({
        url: url,
        method: "GET",
        headers: { "Accept": "application/json; odata=verbose" },
        success: function (data) {
            success(data.d.results);
        },
        error: function (data) {
            failure(data.responseJSON.error);
        }
    });
}


//Usage
getListItems('https://contoso.sharepoint.com/project/','Tasks',function(taskItems){
    console.log(taskItems); 
    for(var i = 0; i < taskItems.length;i++) {
        console.log(taskItems[i].TaskName);
    }
  },
  function(error){
    console.log(JSON.stringify(error));
  }
);

References

Sign up to request clarification or add additional context in comments.

6 Comments

Thanks for the suggestion. I didn't realize that Sharepoint can also do it via listdata.svc. However, it doesn't really work for me. I tried using: sharepointurl/subpage/Lists/_vti_bin/listdata.svc/test%20list and it only displays a white page instead of the list in xml. Also I can't seem to figure out how to select a certain view of that list. Strange thing is that a standard page without lists works and shows the xml code of the site...
I can't even reproduce the white page. If I do the same thing now I get an error message: Request Error: The server encountered an error processing the request. See server logs for more details.
I think I traced the problem back to multi level subpages. If I use sharepointserver/L1Sub/_layouts/_vti_bin/ListData.svc/TestList is working. sharepointserver/L1Sub/L2Sub/_layouts/_vti_bin/ListData.svc/TestList is not working.
hmm, it is a little bit strange, is it so that L1Sub and L2Sub are both sites and TestList list does really exist under L2Sub sub site?
The tables are not the same though, is it possible that special characters break the whole thing? Like the german letters ä,ü,ö,ß
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.