本文整理汇总了C#中ITemplate.ToXml方法的典型用法代码示例。如果您正苦于以下问题:C# ITemplate.ToXml方法的具体用法?C# ITemplate.ToXml怎么用?C# ITemplate.ToXml使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ITemplate
的用法示例。
在下文中一共展示了ITemplate.ToXml方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: SendTemplates
public TemplateResponse SendTemplates(ITemplate template)
{
var templateId = -1;
var error = "unknown";
var status = RequestResultType.Error;
var xml = template.ToXml();
StringBuilder location = new StringBuilder("");
location.Append(_url);
location.Append("/xml/TemplateSubmit.aspx?");
location.Append("UserName=");
location.Append(_user);
location.Append("&UserPassword=");
location.Append(_password);
string response = "";
try
{
response = webClientProxy.UploadString(location.ToString(), xml.ToString());
}
catch (WebException wex)
{
status = RequestResultType.Error;
error = "Server Error: " + wex;
}
catch (TimeoutException tex)
{
status = RequestResultType.Error;
error = "Server Error: " + tex;
}
catch (Exception ex)
{
status = RequestResultType.Error;
error = "Error: " + ex;
}
var xmlDoc = new XmlDocument();
xmlDoc.LoadXml(response);
status = RequestResultType.Success; // we have xml and it parsed correctly, so here we know request was made successfully
var xnList = xmlDoc.SelectNodes("Templates");
if (xnList.Count == 0)
{
error = xmlDoc.SelectNodes("PostAPIResponse/SaveTemplateResult")[0]["Exception"].InnerText;
}
else
{
error = "none";
foreach (XmlNode xn in xnList)
{
try
{
templateId = Convert.ToInt32(xn["TemplateID"].InnerText);
}
catch (Exception)
{
status = RequestResultType.Error;
error = xn["Exception"].InnerText;
}
}
}
return new TemplateResponse { TemplateId = templateId, Status = status, Error = error };
}