Logo 
Search:

Sharepoint Forum

Ask Question   UnAnswered
Home » Forum » Sharepoint       RSS Feeds

Error when submitting batch of METHODs to UpdateListItems of the SP

  Asked By: Stephanie    Date: Jun 04    Category: Sharepoint    Views: 10662

I've got a process that manages the contents of a custom list. The process takes the contents of an AccessDB, runs the data through some logic, and then adds/updates/deletes items from the custom list. All the SharePoint interation is implemented via the SharePoint Lists Web service (lists.asmx) using the UpdateListItems method.

After running into a few problems with what seemed that the XmlElement I was passing in as the BATCH command was way too long so I reduced the batch number. It runs, but it tanks in random spots... always with the following error:

This is an unexpected token. The expected token is 'SEMICOLON'. Line 1, position 16572.

Every time I run it with the same exact dataset, the position number changes... the message stays the same, but the actual posistion changes. I've looked at the source of my query and don't see anything. Here's a sample of one of my batch commands:

<Method ID="9e4bf490-a876-43f7-8b13-eb59b21e63f6" Cmd="New"><Field Name="Title">100-XXX-XXX

XXX-AB000</Field><Field Name="Project_x0020_Leader">John Doe</Field><Field

Name="Lead_x0020_Programmer">John Doe</Field><Field Name="Analyst">John

Doe</Field><Field Name="Seller_x0020_Number">999</Field><Field Name="Seller_x0020_Name">Some

Company Name</Field><Field Name="Client_x0020_Number">100</Field><Field

Name="Client_x0020_Name">Some Company Name</Field><Field Name="Number_x0020_of_x0020_Loans">9999</Field>

<Field Name="System">Some System</Field><Field Name="Project_x0020_Type">Some

Project</Field><Field Name="Line_x0020_of_x0020_Business">XXX</Field><Field

Name="Project_x0020_Number">PROJ1111</Field><Field Name="Event_x0020_Description">Project

End Date</Field><Field Name="Event_x0020_Date">2004-04-16</Field></Method>

Code that's throwing an error:

What I'm doing is putting all the CAML commands (the METHOD node listed above, as type string, not XmlNode/XmlElement) in a queue and batch sending them to the list. Once I have filled up the queue, the code proceeds to the batch processing portion where it deques a chunck of strings and appends it using a StringBuilder. I then create a new XmlDocument, create a root BATCH node, set the OnError attribute, and add all the METHOD nodes to the InnerXml property of the batch node as follows:

XmlDocument xDoc = new XmlDocument();

// create a batch to send to the Web service

XmlElement xBatch = xDoc.CreateElement("Batch");

xBatch.SetAttribute("OnError", "Continue");

// get one string of all the objects in the queue

StringBuilder camlMethods = new StringBuilder();

int queueSize = GetQueue().Count;

for (int i = 0; i < queueSize; i++)

camlMethods.Append(GetQueue().Dequeue());

// nothing should be left in the queue

Debug.Assert(GetQueue().Count == 0, "GetQueue().Count == 0", "Queue should be empty here; instead count =" +GetQueue().Count.ToString());

// add all methods -> batch

xBatch.InnerXml = camlMethods.ToString();

return xBatch; // the return type of the method is XmlElement

The error is being thrown on the last line above. I checked the error in an XML NNTP and saw where it was commonly found when you don’t quote your attributes correctly. Looking at the resulting XML, everything looks good. I’ve even dumped it to a XML file and opened it in XMLSpy to verify it’s valid XML.

I followed this example:

blogs.msdn.com/.../239968.aspx

After searching through the

Ideas?

Share: 

 

2 Answers Found

 
Answer #1    Answered By: Ciara Collier     Answered On: Jun 04

A few thoughts …

1) I assume the method  ID is a randomly generated Guid. So the chance of collision is low.

2) I assume that you’re doing an encoding of the data  going into the queue so you don’t have any stray characters. My personal favorite character is the apostrophe – it doubles as a single quote so it is sometimes misinterpreted. I can’t remember if the lists  service allows you to use CDATA sections in your XML or not – but if it’s an easy change I’d test that pretty quickly.

3) I’m not precisely clear on what’s in your queue – if it is individual method nodes … try adding them to the XML individually instead of all at once at the end.

 
Answer #2    Answered By: Keenan Whitehead     Answered On: Jun 04

I took your third bullet, rewrote how I was building the batch  XmlElement, added some debugging & asserts, which yielded that your second bullet was the culprit: although we said data  coming to the process  must be HTML encoded, it apparently wasn’t (that was BAD of me to assume I was getting clean data)… it had an & in one of the strings.

For anyone else, here’s the code that was more methodical…


XmlDocument xDoc = new XmlDocument();

// create a batch to send to the Web service

XmlElement xBatch = xDoc.CreateElement("Batch");

xBatch.SetAttribute("OnError", "Continue");

// get one string of all the objects in the queue

int queueSize = GetQueue().Count;

string queueContents;

for (int i = 0; i < queueSize; i++)

{

// get the method  xml command

queueContents = GetQueue().Dequeue() as string;

Debug.WriteLine(queueContents);

Debug.Assert(queueContents != null, "queueContents != null");

// load the METHOD XML
xDoc.LoadXml(queueContents);
// add it to the batch

xBatch.AppendChild(xDoc.FirstChild);

}

// nothing should be left in the queue

Debug.Assert(GetQueue().Count == 0, "GetQueue().Count == 0", "Queue should be empty here; instead count =" +GetQueue().Count.ToString());

return xBatch;

 




Tagged: