This project has moved. For the latest updates, please go here.

UpdateListItems issue handling tags in text fields

Jan 13, 2011 at 5:44 PM

I am certainly having way to much fun with SPServices!!

I have been working on a way to bring in RSS feeds into a list, without creating duplicates, to allow adding our own metadata alongside the feed.  This will be particularly helpful when reading in information from one SharePoint site to another.

The only issue I am encountering is that information comes in (via jFeed which I highly recommend) the rss description field, which I then pass it to a new item's Description field (multiline - plain text, rich text, does not matter) - it drops the text as soon as it reaches the first tag.  For most RSS feeds this is fine, I simply lose all the social media tags, but with a SharePoint list, the first value in the rss description field is always <div>.

I was looking for a way to handle this, without going through a painful split process that would be unique to every list I encounter.

Is there any way to get the SPService to bring in the text, and ignore the fact that the tags are there?

Here is my code - thanks!!

<SCRIPT type=text/javascript src="http://idnetmonitor/sites/rc/mastercode/jquery.current.min.js"></SCRIPT>
<SCRIPT type=text/javascript src=""></SCRIPT>
<SCRIPT type=text/javascript src="http://idnetmonitor/sites/rc/mastercode/jquery.SPServices.current.min.js"></SCRIPT>
<SCRIPT type=text/javascript>

function CopyRSS()

$(document).ready(function() {

// getting the information for each item in the RSS feed, returned as variables item.title,,, item.description, item.updated

      url: '',
      success: function(feed) {

            var html = '';
            for(var i = 0; i < feed.items.length && i < 250; i++) {
             var item = feed.items[i];

// getting a count of rows where the already exists in the list
        operation: "GetListItems",
        async: false,
        listName: "cnn2",
        CAMLViewFields: "<ViewFields><FieldRef Name='FeedID' /></ViewFields>",
        CAMLQuery: "<Query><Where><Eq><FieldRef Name='FeedID' /><Value Type='Text'>" + + "</Value></Eq></Where></Query>",
        CAMLRowLimit: 1,
        completefunc: function (xData, Status) {
        $(xData.responseXML).find("rs\\:data").each(function() {
          var  itemCount = $(this).attr("ItemCount");

//  if the row count = 0, i.e. the item is not already in the list, it is added

	        operation: "UpdateListItems",
	        async: false,
	        listName: "cnn2",
	        updates: "<Batch OnError='Continue' PreCalc='TRUE'>" +
	                    "<Method ID='1' Cmd='New'>" +
	                        "<Field Name='Title'>" + item.title + "</Field>" +
	                        "<Field Name='Link'>" + + "</Field>" +
	                        "<Field Name='Updated'>" + item.updated + "</Field>" +
	                        "<Field Name='FeedID'>" + + "</Field>" +
	                        "<Field Name='Description'>" + item.description + "</Field>" +
	                    "</Method>" +
	        completefunc: function (xData, Status) {


<input type=button value="Create List Items from RSS feed" onClick="javascript:CopyRSS();"/>
Jan 13, 2011 at 5:50 PM

More robust searching in the discussions came up with this little piece of code, which I am not sure how to use to clean up the variable item.description that the jFeed retrieves:

function escapeHTMLEncode(str) {
              var div = document.createElement('div');
              var text = document.createTextNode(str);
              return div.innerHTML;

Am a JavaScript novice - how would this be used in my code? will it clean up all "<" and ">".



Jan 15, 2011 at 3:59 PM


I think it is indeed an escaping issue. You need to pass the item.description escaped for it to "make it" into the list item.

There's a private function in SPServices that I use to do this, and you could do the same:

 // Escape string characters
 function escapeHTML(s) {
  return s.replace(/&/g,'&amp;').replace(/"/g,'&quot;').replace(/</g,'&lt;').replace(/>/g,'&gt;');

So, to just plant the logic directly into your code:

 "<Field Name='Description'>" + item.description.replace(/&/g,'&amp;').replace(/"/g,'&quot;').replace(/</g,'&lt;').replace(/>/g,'&gt;') + "</Field>" +


Jan 18, 2011 at 1:04 PM


That worked perfectly - now RSS feeds I pull in from commercial resources, as well as from internal SharePoint lists come out formatted beautifully.

Thanks so much for your guidance!


Jan 18, 2011 at 1:09 PM

Excellent! And you're welcome.