本文整理汇总了C#中XmlDocument.ToXml方法的典型用法代码示例。如果您正苦于以下问题:C# XmlDocument.ToXml方法的具体用法?C# XmlDocument.ToXml怎么用?C# XmlDocument.ToXml使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类XmlDocument
的用法示例。
在下文中一共展示了XmlDocument.ToXml方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetWeatherData
public string GetWeatherData()
{
try
{
string url = weatherLocation + zipCode;
XmlDocument doc = new XmlDocument();
string cachedXml = Services.Get<ICache>().Get(url) as string ?? string.Empty;
if (string.IsNullOrEmpty(cachedXml))
doc.Load(url);
else
doc.LoadXml(cachedXml);
if (null == Services.Get<ICache>().Get(url))
Services.Get<ICache>().Add(url, doc.ToXml());
XmlElement root = doc.DocumentElement;
XmlNodeList nodes = root.SelectNodes("/rss/channel/item");
string data = "";
foreach (XmlNode node in nodes)
{
data = data + node["title"].InnerText;
data = data + node["description"].InnerText;
}
return data;
}
catch
{
return string.Empty;
}
}
示例2: GetHoroscope
public string GetHoroscope()
{
try
{
SetHoroscopeData();
string imgName = ddlHoroscope.SelectedItem.Text.ToLower() + ".gif";
string data = "";
data = "<img src='Widgets/Horoscope_image/" + imgName + "'/><br/><b> " + strHoroscope[ddlHoroscope.SelectedIndex] + "</b>";
XmlDocument doc = new XmlDocument();
string cachedXml = Services.Get<ICache>().Get(rssLocation) as string ?? string.Empty;
try
{
if (string.IsNullOrEmpty(cachedXml))
doc.Load(rssLocation);
else
doc.LoadXml(cachedXml);
}
catch
{
return string.Empty;
}
if (null == Services.Get<ICache>().Get(rssLocation))
Services.Get<ICache>().Add(rssLocation, doc.ToXml());
XmlElement root = doc.DocumentElement;
XmlNodeList nodes = root.SelectNodes("/rss/channel/item");
foreach (XmlNode node in nodes)
{
string str = node["title"].InnerText;
if (str.StartsWith(ddlHoroscope.SelectedItem.Text))
{
data = data + node["description"].InnerText;
data = data.Remove(data.IndexOf("More horoscopes!"));
}
}
return data;
}
catch
{
return string.Empty;
}
}