同样,要获取从 Sharepoint 2010 对象模型返回的列表项,该列表项可以在 C# 中使用 xml 中关键节点的对应值,我们必须摆脱附加在 xml 中位置 1 处的附加字符。这可以按如下方式完成:
// 用于破译从 SharePoint Server 2010 对象模型列表项返回的 XML 字符串的代码。- 礼貌 - Rajiv Kapoor - Ideals.co.in。查看http://www.ideals.co.in/estore/code.php以获得完整的解决方案。
string sRetVal = "";
string myXMLStr = "<robot><Key>ConstSigned</Key><Value>Rad Is Signed</Value><Key>CodeAddChangeReqSub</Key><Value>ACRS</Value><Key>CodeAddChangeReqInit</Key><Value>ACRI</Value><Key>CodeSupTaskComp</Key><Value>STC</Value><Key>CodeSupApprComp</Key><Value>SAC</Value><Key>CodeSupRejComp</Key><Value>SAR</Value><Key>CodeOperAppr</Key><Value>OPA</Value><Key>CodeOperRej</Key><Value>OPR</Value><Key>Oper1TaskCreated</Key><Value>OTC</Value><Key>Oper2TaskCreated</Key><Value>QCTC</Value><Key>Oper2TaskAppr</Key><Value>QCRA</Value><Key>Oper2TaskRej</Key><Value>QCRR</Value><Key>ApprPending</Key><Value>Approval Pending</Value><Key>PendingProcessing</Key><Value>Pending Processing</Value><Key>PendingReview</Key><Value>Pending Review</Value><Key>Approved</Key><Value>Approved</Value><Key>GroupOperation</Key><Value>Operation</Value><Key>WorkFlowHistoryList</Key><Value>/Lists/Workflow History</Value><Key>ColInitDateTime</Key><Value>Initiated Date Time</Value><Key>ColWorkFlowHistoryParentInst</Key><Value>Workflow History Parent Instance</Value><Key>ColWorkflowAssId</Key><Value>Workflow Association ID</Value><Key>ColListId</Key><Value>List ID</Value><Key>ColPrimaryItemId</Key><Value>Primary Item ID</Value><Key>ColDate</Key><Value>Date Occurred</Value><Key>ColOutcome</Key><Value>Outcome</Value><Key>ColDesc</Key><Value>Description</Value><Key>ColCreated</Key><Value>Created</Value><Key>ColTaskStatus</Key><Value>TaskStatus</Value><Key>ServiceReqList</Key><Value>Service Request</Value><Key>CAUEventList</Key><Value>Events</Value><Key>ReqStatus1</Key><Value>Request Status</Value><Key>ReqStatCode</Key><Value>Request Status Code</Value><Key>ColumnCode</Key><Value>Code</Value><Key>SuperUser</Key><Value>SuperUser</Value><Key>AssignedTo</Key><Value>AssignedTo</Value><Key>TaskListId</Key><Value>ID</Value><Key>DocLibId</Key><Value>List</Value><Key>WorkflowInstanceId</Key><Value>WorkflowInstanceID</Value><Key>TaskTitle</Key><Value>Title</Value><Key>Priority</Key><Value>Priority</Value><Key>ReqStatusCode</Key><Value>Request Status Code</Value><Key>ServiceRequestList</Key><Value>Service Request</Value><Key>CAUEventList</Key><Value>Events</Value><Key>ColumnDesc</Key><Value>Description</Value><Key>ColumnStatus</Key><Value>Status</Value><Key>Completed</Key><Value>Completed</Value><Key>ReqStatus</Key><Value>Request Status</Value><Key>ColumnTaskStatus</Key><Value>TaskStatus</Value><Key>ColumnPerComp</Key><Value>PercentComplete</Value><Key>Rejected</Key><Value>Rejected</Value><Key>CodeSupTaskCreated</Key><Value>STC</Value><Key>CodeSupTaskInit</Key><Value>SAI</Value><Key>Oper1TaskInit</Key><Value>OPI</Value><Key>Oper2TaskInit</Key><Value>QCRI</Value><Key>ColActedBy</Key><Value>Acted By</Value><Key>WorkFlowCode</Key><Value>Workflow Code</Value><Key>ProcCode</Key><Value>Process Code</Value></robot>";
string myXMLStr1 = myXMLStr;
int ln = myXMLStr.Length;
int lnMinus1 = ln - 1;
char[] myst = { ' ', ' ', ' '};// create a long array enough to fit the xml
string mys = "";
object m1 ;
string m2 = "";
myXMLStr.CopyTo(0, myst, 0, ln); m1 = myst.Clone();
m2 = new string(myst);// m1;// ToString();
m2.TrimStart();
m2.TrimEnd();
m2 = m2.Substring(1);
sRetVal = GetConfigVal(m2, "ProcCode");
Console.WriteLine("****#*" + sRetVal + "*#******");