我想将List响应作为xml文档传递,并希望将其作为xml加载。 目前我正在使用此代码执行它:
List<string> BugWSResponseList1 = new List<string>();
BugWSResponseList1 = CreateBugs(FilePath_EXPRESS_API_BugAdd_CreateBugs_DataFile, newValue);
XmlDocument xd = new XmlDocument();
//string s = string.Join(",", BugWSResponseList2);
//xd.LoadXml(s);
string s = "<Bugs>" + string.Join(",", BugWSResponseList1) + "</Bugs>";
xd.LoadXml(s);
//Dictionary Creation for Benchmark API
XmlDocument ResponseNode_bugs = null;
ResponseNode_bugs = new DrWatsonCore().LoadXMLDocument(s);
我想避免首先将List<string>
响应转换为字符串,然后将其作为xml加载。
请建议我如何实现这一目标。
请查看我的LoadXMLDocument
功能的详细信息,如下所示:
public XmlDocument LoadXMLDocument(string XMLData)
{
XmlDocument doc = new XmlDocument();
try
{
doc.LoadXml(XMLData);
}
catch (Exception ex)
{
Logger.Write("\n\n" + DateTime.Now + " : " + "LoadXMLDocument : SEVERE ERROR : Failed to create XMLDocument from given string : \n\n");
Logger.Write("\n\n" + DateTime.Now + " : " + "Exception : : \n\n" + ex.Message);
Logger.Write("\n\n" + DateTime.Now + " : " + "Given String : : \n\n");
if (DrWatsonHome.doVerboseLogging)
{
Logger.Write(XMLData);
}
else
{
string Response = XMLData;
Logger.Write("\n\n" + DateTime.Now + " : " + "Response Length : " + Response.Length + " characters.");
int ResponseLengthToPrint = DrWatsonHome.VerboseLogging_Length_Chars < Response.Length ? DrWatsonHome.VerboseLogging_Length_Chars : Response.Length;
Logger.Write("\n\n" + DateTime.Now + " : " + "Response : " + Response.Substring(0, ResponseLengthToPrint) + " ...");
}
}
finally
{
}
return doc;
}
我可以在对其进行一些修改后实现它。请建议。
我现在正在使用List,我的功能如下:
List<XElement> Sairam(string FilePath, string Timestamp)
{
List<XElement> WSResponse = new List<XElement>();
XmlDocument XDoc = new DrWatsonCore().LoadXMLFromFile(FilePath);
XmlNode BugListNode = XDoc.SelectSingleNode("/DrWatson/Bugs");
List<Bug> BugList = new DrWatsonCore().GetBugList(BugListNode);
List<Thread> BugFtecherThreadList = new List<Thread>();
foreach (Bug bug in BugList)
{
bug.FoundInBuild = Timestamp;
string URL = new DrWatsonCore().CreateWXURL(EXPRESS_API_METHOD.bug_add, bug, REST_EndPoint, AppGUID, new WatsonUser(Username_Watson, Password_Watson));
string Response = string.Empty;
object URLobj = (object) URL;
Response = CreateBug(URLobj);
// WSResponse.Add(Response);
}
return WSResponse;
}
我想将WSResponse作为程序的最终响应,但我无法获取它。请建议如何从此功能获得该程序的响应。