本文整理匯總了C#中Sgml.SgmlReader.ReadOuterXml方法的典型用法代碼示例。如果您正苦於以下問題:C# SgmlReader.ReadOuterXml方法的具體用法?C# SgmlReader.ReadOuterXml怎麽用?C# SgmlReader.ReadOuterXml使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Sgml.SgmlReader
的用法示例。
在下文中一共展示了SgmlReader.ReadOuterXml方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。
示例1: GetXmlFromHtmlString
public static String GetXmlFromHtmlString (String html)
{
using (SgmlReader sr = new SgmlReader())
{
sr.InputStream = new StringReader(html);
return sr.ReadOuterXml();
}
}
示例2: getXmlReader
//private static Value getDocXml (String uri, String path, HttpContext context)
//{
// try
// {
// return Value.asValue(getXdmNode(uri, path, context).Unwrap());
// }
// catch (Exception e)
// {
// throw;
// }
//}
private static String getXmlReader (String uri, String path, HttpContext context)
{
string decodedUri = HttpUtility.UrlDecode(uri);
string eTag = Context.GenerateETag(decodedUri, Nuxleus.Cryptography.HashAlgorithm.SHA1);
String xhtml = String.Empty;
try
{
if (m_CacheDictionary.ContainsKey(eTag))
{
xhtml = m_CacheDictionary[eTag];
}
else
{
using (SgmlReader sr = new SgmlReader())
{
try
{
if ((bool)context.Application["usememcached"])
{
MemcachedClient m_client = (MemcachedClient)context.Application["memcached"];
if (m_client.KeyExists(eTag))
{
sr.InputStream = GetStreamFromHtmlString((string)m_client.Get(eTag));
}
else
{
sr.Href = decodedUri;
m_client.Add(eTag, sr.ReadOuterXml(), DateTime.Now.AddMinutes(60));
}
}
else
{
sr.Href = decodedUri;
}
}
catch (Exception e)
{
Console.WriteLine(e.Message);
Console.WriteLine(e.StackTrace);
}
xhtml = sr.ReadOuterXml();
m_CacheDictionary.Add(eTag, xhtml);
}
}
return xhtml;
}
catch (Exception e)
{
Console.WriteLine(e.Message);
Console.WriteLine(e.StackTrace);
}
return String.Format(@"<html xmlns='http://www.w3.org/1999/xhtml'>
<head>
<title>No Readable HTML</title>
</head>
<body>
<h1>No readable HTML was located at the specified URL</h1>
</body>
</html>");
}
示例3: GetXmlFromHtmlString
public static XNode GetXmlFromHtmlString(String html)
{
using (SgmlReader sr = new SgmlReader())
{
string htmlWrapper = String.Format("<div xmlns=\"http://www.w3.org/1999/xhtml\">{0}</div>", html);
try
{
sr.InputStream = new StringReader(htmlWrapper);
return XElement.Parse(sr.ReadOuterXml(), LoadOptions.None);
}
catch
{
return new XText(HttpUtility.HtmlEncode(html));
}
}
}