我想将 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 作为程序的最终响应,但我无法获取它。请提出建议,我怎样才能从这个函数中得到这个程序的响应。