本文整理匯總了C#中Sgml.SgmlReader.GetAttribute方法的典型用法代碼示例。如果您正苦於以下問題:C# SgmlReader.GetAttribute方法的具體用法?C# SgmlReader.GetAttribute怎麽用?C# SgmlReader.GetAttribute使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Sgml.SgmlReader
的用法示例。
在下文中一共展示了SgmlReader.GetAttribute方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。
示例1: GetAttributeValues
public static IEnumerable<string> GetAttributeValues(this string html, string tagName, string attributeName)
{
var reader = new SgmlReader
{
DocType = "html",
WhitespaceHandling = WhitespaceHandling.All,
InputStream = new StringReader(string.Format("<html>{0}</html>", html))
};
while (reader.Read() && !reader.EOF)
{
if (reader.NodeType == XmlNodeType.Element && reader.LocalName == tagName)
{
yield return reader.GetAttribute(attributeName);
}
}
}
示例2: AddVideo
public static AlbumItem AddVideo(UserContainer currContext, Guid albumId, string title, string description, string url, string embedCode)
{
var album = DataService.PerThread.AlbumSet.SingleOrDefault(x => x.Id == albumId);
if (album == null)
throw new BusinessLogicException("Указан неверный идентификатор");
if (string.IsNullOrWhiteSpace(title))
throw new BusinessLogicException("Не указано название видео");
if (currContext != null)
{
if (album.GroupId.HasValue)
{
var gm = GroupService.UserInGroup(currContext.Id, album.GroupId.Value);
if (gm == null)
throw new BusinessLogicException("Вы не состоите в группе");
if (album.IsOpen)
{
if (!(gm.State == (byte)GroupMemberState.Approved || gm.State == (byte)GroupMemberState.Moderator))
throw new BusinessLogicException("Только члены группы могут добавлять видео в альбом");
}
else if (gm.State != (byte)GroupMemberState.Moderator)
throw new BusinessLogicException("Только модераторы могут добавлять видео в альбом");
}
else if (album.UserId.HasValue)
{
if (album.UserId != currContext.Id)
throw new BusinessLogicException("Нельзя добавлять видео в чужой альбом");
}
else
throw new BusinessLogicException("Альбом ни к чему не привязан");
}
string src;
if (!string.IsNullOrWhiteSpace(embedCode))
{
using (var sgml = new SgmlReader())
{
sgml.InputStream = new StringReader(embedCode);
sgml.Read();
src = sgml.GetAttribute("src");
}
}
else if (!string.IsNullOrWhiteSpace(url))
{
var uri = new Uri(url);
src = url; // TODO: мб лучше regexp для вычленения src
switch (uri.Host.Replace("www.", string.Empty))
{
case "youtube.com":
//src = uri.Scheme + "://" + uri.Host + "/embed/" + HttpUtility.ParseQueryString(uri.Query).GetValues("v").First(); // это для iframe
src = uri.Scheme + "://" + uri.Host + "/v/" + HttpUtility.ParseQueryString(uri.Query).GetValues("v").First();
break;
case "youtu.be":
//src = uri.Scheme + "://youtube.com/embed/" + uri.Segments[1]; // это для iframe
src = uri.Scheme + "://youtube.com/v/" + uri.Segments[1];
break;
/*case "vimeo.com":
src = uri.Scheme + "://" + "player." + uri.Host + "/video" + uri.PathAndQuery;
break;
case "dailymotion.com":
var query = uri.Fragment.Replace("#", string.Empty);
src = uri.Scheme + "://" + uri.Host + "/embed/video/" + HttpUtility.ParseQueryString(query).GetValues("videoId").First();
break;*/
case "e2-e4.tv":
src = uri.Scheme + "://" + uri.Host + uri.PathAndQuery + "/swf/player2.swf";
break;
case "e2e4.tv":
src = uri.Scheme + "://" + uri.Host + uri.PathAndQuery + "/swf/player2.swf";
break;
}
}
else
throw new BusinessLogicException("Источник видео не указан");
var albumItem = new AlbumItem
{
AlbumId = albumId,
Title = title,
Description = description,
Type = (byte)AlbumItemType.Video,
Src = src,
CreationDate = DateTime.Now
};
DataService.PerThread.AlbumItemSet.AddObject(albumItem);
DataService.PerThread.LoadProperty(albumItem, x => x.Album);
albumItem.Album.ChangeDate = DateTime.Now;
DataService.PerThread.SaveChanges();
//.........這裏部分代碼省略.........
示例3: LoadHtml
public void LoadHtml(string rawHtml)
{
if (rawHtml.StartsWith("<dsi:html"))
{
//parse and remove dsi:html tag...
string tag = rawHtml.Substring(0, rawHtml.IndexOf('>') + 1) + "</dsi:html>";
rawHtml = rawHtml.Substring(rawHtml.IndexOf('>') + 1);
rawHtml = rawHtml.Substring(0, rawHtml.Length - 11);
/*
<dsi:html
formatting = [true | false] // do we convert line-breaks to br tags?
container = [true | false] // do we render the html in a container div?
></dsi:html>
*/
SgmlReader sgml = new SgmlReader();
sgml.InputStream = new StringReader(tag);
sgml.DocType = "HTML";
sgml.Read();
if (sgml.GetAttribute("formatting") != null)
Formatting = bool.Parse(sgml.GetAttribute("formatting"));
if (sgml.GetAttribute("container") != null)
Container = bool.Parse(sgml.GetAttribute("container"));
}
this.rawHtml = rawHtml;
}