0

I am trying to get some contents from an excelsheet via excelrest.aspx with jquery. I am using following code to read the value of x:fv, however it either throws an error message or ends up with empty value. If instead of x:fv I try to read the contents of the update tag it works fine; so I assume there's a problem with the syntax of x:fv.

jQuery.ajax({
    type: "GET",
    url: "/sales/_vti_bin/ExcelRest.aspx/Structured%20Notes%202/test.xlsx/model/ranges('Issuer')?$format=atom",
    dataType: "xml",
    success: function(xml){
        $(xml).find('entry').each(function(){
            var sTitle = $(this).find("x:fv").text();
            alert(sTitle);
        });
    },
    error: function() {
        alert("An error occurred while processing XML file.");
    }
});
<?xml version="1.0" encoding="utf-8"?>
<entry xmlns:x="http://schemas.microsoft.com/office/2008/07/excelservices/rest" xmlns:d="http://schemas.microsoft.com/ado/2007/08/dataservice" xmlns:m="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata" xmlns="http://www.w3.org/2005/Atom">
  <title type="text">Issuer</title>
  <id>https://x.sharepoint.com/sales/_vti_bin/ExcelRest.aspx/Structured%20Notes%202/test.xlsx/Model/Ranges('Issuer')</id>
  <updated>2013-12-20T08:47:40Z</updated>
  <author>
    <name />
  </author>
  <link rel="self" href="https://x.sharepoint.com/sales/_vti_bin/ExcelRest.aspx/Structured%20Notes%202/test.xlsx/Model/Ranges('Issuer')?$format=atom" title="Issuer" />
  <category term="ExcelServices.Range" scheme="http://schemas.microsoft.com/ado/2007/08/dataservices/scheme" />
  <content type="application/xml">
    <x:range name="Issuer">
      <x:row>
        <x:c>
          <x:fv>test</x:fv>
        </x:c>
      </x:row>
    </x:range>
  </content>
</entry>
Dan Lowe
  • 51,713
  • 20
  • 123
  • 112
Paul77
  • 1

3 Answers3

0

parse the xml after receiving

  success: function(xml){
    var xmlDoc = $.parseXML(xml)
     $(xmlDoc).find('entry').each(function(){
       var sTitle = $(this).find("x:fv").text();
       alert(sTitle);
    });
  },

reference

Bhadra
  • 2,121
  • 1
  • 13
  • 19
0

Try .contents() after your request in your success functions like this :

success: function(xml){
    $(xml).contents().find('entry').each(function(){
      var sTitle = $(this).find("x:fv").text();
           alert(sTitle);
    }
Lamari Alaa
  • 158
  • 7
0

It took me forever to find, but it seems the parser doesn't like the colon. This worked for me (where "url" is a variable defined earlier with the path to my XL Services Rest API):

jQuery.ajax({   
  type: "GET",   
  url: url,   
  dataType: "xml",
  async:   false,
  success: function (data) {   
    $(data).find('x\\:fv').each(function(){
    var optionText = $(this).text();
  });
},   
error: function (xhr, msg, e) {   
  alert("Error: The section data cannot be found. Has the underlying file been deleted or moved?");
  }   
});

Note that the decision to NOT call the function asynchronously should have no effect. I'm calling it synchronously for reasons of my own.

drasmu
  • 1
  • 1