本文整理匯總了C#中Sgml.SgmlReader.MoveToNextAttribute方法的典型用法代碼示例。如果您正苦於以下問題:C# SgmlReader.MoveToNextAttribute方法的具體用法?C# SgmlReader.MoveToNextAttribute怎麽用?C# SgmlReader.MoveToNextAttribute使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Sgml.SgmlReader
的用法示例。
在下文中一共展示了SgmlReader.MoveToNextAttribute方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。
示例1: FindImgs
internal static ImageInfo[] FindImgs(
string htmlCode)
{
var r =
new SgmlReader
{
DocType = @"HTML",
InputStream = new StringReader(htmlCode)
};
var al = new List<ImageInfo>();
//find <img src=""
while (r.Read())
{
if (r.NodeType == XmlNodeType.Element)
{
if (string.Compare(r.Name, @"img", StringComparison.OrdinalIgnoreCase) == 0)
{
if (r.HasAttributes)
{
var ii = new ImageInfo();
while (r.MoveToNextAttribute())
{
switch (r.Name.ToLowerInvariant())
{
case @"src":
ii.Source = r.Value;
break;
case @"width":
ii.Width = ConvertHelper.ToInt32(r.Value);
break;
case @"height":
ii.Height = ConvertHelper.ToInt32(r.Value);
break;
}
}
// --
if (!string.IsNullOrEmpty(ii.Source))
{
al.Add(ii);
}
}
}
}
}
return al.ToArray();
}
示例2: Test_MoveToNextAttribute
public void Test_MoveToNextAttribute()
{
// Make sure we can do MoveToElement after reading multiple attributes.
var r = new SgmlReader {
InputStream = new StringReader("<test id='10' x='20'><a/><!--comment-->test</test>")
};
Assert.IsTrue(r.Read());
while(r.MoveToNextAttribute()) {
_log.Debug(r.Name);
}
if(r.MoveToElement()) {
_log.Debug(r.ReadInnerXml());
}
}
示例3: RegressionTest1
void RegressionTest1()
{
// Make sure we can do MoveToElement after reading multiple attributes.
SgmlReader r = new SgmlReader();
r.InputStream = new StringReader("<test id='10' x='20'><a/><!--comment-->test</test>");
if (r.Read()) {
while (r.MoveToNextAttribute()) {
Trace.WriteLine(r.Name);
}
if (r.MoveToElement()) {
Trace.WriteLine(r.ReadInnerXml());
}
}
}
示例4: dsiTagReplacement
public string dsiTagReplacement(Match m)
{
string tagName = "dsi";
try
{
//string[] arrParts = m.Groups[1].Value.Split[" "];
//Dictionary<string, string> parts = new Dictionary<string, string>();
SgmlReader sgml = new SgmlReader();
string inStr = m.Groups[0].Value;
if (inStr.StartsWith("<dsi:link"))
inStr += "</dsi:link>";
sgml.InputStream = new StringReader(inStr);
sgml.DocType = "HTML";
sgml.Read();
tagName = sgml.Name;
string uniqueId = Guid.NewGuid().ToString("N");
#region Parse attributes
Dictionary<string, string> attributes = new Dictionary<string, string>();
while (sgml.MoveToNextAttribute())
{
attributes.Add(sgml.Name.ToLower(), sgml.Value);
}
#endregion
string typeAtt = attributes.ContainsKey("type") ? attributes["type"] : null;
string refAtt = attributes.ContainsKey("ref") ? attributes["ref"] : null;
#region Parse styles
Dictionary<string, string> style = new Dictionary<string, string>();
if (attributes.ContainsKey("style"))
{
foreach (string s in attributes["style"].Split(';'))
{
try
{
if (s.Contains(":"))
style[s.Split(':')[0].Trim()] = s.Split(':')[1].Trim();
}
catch
{
}
}
}
#endregion
#region Parse class
List<string> classes = new List<string>();
if (attributes.ContainsKey("class"))
{
foreach (string s in attributes["class"].Split(' '))
{
try
{
classes.Add(s);
}
catch
{
}
}
}
#endregion
if (tagName == "dsi:video")
{
#region dsi:video
/*
<dsi:video
type = [dsi | flv | youtube | google | metacafe | myspace | break | collegehumor | redtube | ebaumsworld | dailymotion]
ref = [dsi-photo-k | site-ref]
src = [flv-url]
width = [width] (optional)
height = [height] (optional)
nsfw = [true | false] (optional)
/>
*/
bool nsfw = attributes.ContainsKey("nsfw") ? bool.Parse(attributes["nsfw"].ToLower()) : false;
string draw = attributes.ContainsKey("draw") ? attributes["draw"].ToLower() : "auto";
if (typeAtt == "youtube")
{
#region youtube
int width = attributes.ContainsKey("width") ? int.Parse(attributes["width"]) : 425;
int height = attributes.ContainsKey("height") ? int.Parse(attributes["height"]) : 355;
//<object width="425" height="355"><param name="movie" value="http://www.youtube.com/v/8VtWo8tFdPQ&rel=1"></param><param name="wmode" value="transparent"></param><embed src="http://www.youtube.com/v/8VtWo8tFdPQ&rel=1" type="application/x-shockwave-flash" wmode="transparent" width="425" height="355"></embed></object>
return GetFlash(uniqueId, height, width, nsfw, draw, "http://www.youtube.com/v/" + refAtt + "&rel=1");
#endregion
}
else if (typeAtt == "metacafe")
{
#region metacafe
int width = attributes.ContainsKey("width") ? int.Parse(attributes["width"]) : 400;
int height = attributes.ContainsKey("height") ? int.Parse(attributes["height"]) : 345;
//<embed src="http://www.metacafe.com/fplayer/1029494/how_to_make_fire_balls.swf" width="400" height="345" wmode="transparent" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash"> </embed><br><font size = 1><a href="http://www.metacafe.com/watch/1029494/how_to_make_fire_balls/">How To Make Fire Balls</a> - <a href="http://www.metacafe.com/">The funniest videos clips are here</a></font>
return GetFlash(uniqueId, height, width, nsfw, draw, "http://www.metacafe.com/fplayer/" + refAtt + ".swf");
#endregion
}
else if (typeAtt == "google")
//.........這裏部分代碼省略.........