本文整理匯總了C#中Sgml.SgmlReader.MoveToAttribute方法的典型用法代碼示例。如果您正苦於以下問題:C# SgmlReader.MoveToAttribute方法的具體用法?C# SgmlReader.MoveToAttribute怎麽用?C# SgmlReader.MoveToAttribute使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Sgml.SgmlReader
的用法示例。
在下文中一共展示了SgmlReader.MoveToAttribute方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。
示例1: Debug
void Debug(SgmlReader sr)
{
NodeTypeFlags[] AllowedContentMap = new NodeTypeFlags[19] {
NodeTypeFlags.None, // none
NodeTypeFlags.Element | NodeTypeFlags.Attribute | NodeTypeFlags.Text | NodeTypeFlags.CDATA | NodeTypeFlags.EntityReference | NodeTypeFlags.ProcessingInstruction | NodeTypeFlags.Comment | NodeTypeFlags.Whitespace | NodeTypeFlags.SignificantWhitespace | NodeTypeFlags.EndElement, // element
NodeTypeFlags.Text | NodeTypeFlags.EntityReference, // attribute
NodeTypeFlags.None, // text
NodeTypeFlags.None, // cdata
NodeTypeFlags.None, // entity reference
NodeTypeFlags.None, // entity
NodeTypeFlags.None, // processing instruction
NodeTypeFlags.None, // comment
NodeTypeFlags.Comment | NodeTypeFlags.DocumentType | NodeTypeFlags.Element | NodeTypeFlags.EndElement | NodeTypeFlags.ProcessingInstruction | NodeTypeFlags.Whitespace | NodeTypeFlags.SignificantWhitespace | NodeTypeFlags.XmlDeclaration, // document
NodeTypeFlags.None, // document type
NodeTypeFlags.None, // document fragment (not expecting these)
NodeTypeFlags.None, // notation
NodeTypeFlags.None, // whitespace
NodeTypeFlags.None, // signification whitespace
NodeTypeFlags.None, // end element
NodeTypeFlags.None, // end entity
NodeTypeFlags.None, // filler
NodeTypeFlags.None, // xml declaration.
};
Stack s = new Stack();
while (sr.Read()) {
if (sr.NodeType == XmlNodeType.EndElement) {
s.Pop();
}
if (s.Count > 0) {
XmlNodeType pt = (XmlNodeType)s.Peek();
NodeTypeFlags p = NodeTypeMap[(int)pt];
NodeTypeFlags f = NodeTypeMap[(int)sr.NodeType];
if ((AllowedContentMap[(int)pt]& f) != f) {
Console.WriteLine("Invalid content!!");
}
}
if (s.Count != sr.Depth-1) {
Console.WriteLine("Depth is wrong!");
}
if ( (sr.NodeType == XmlNodeType.Element && !sr.IsEmptyElement) ||
sr.NodeType == XmlNodeType.Document) {
s.Push(sr.NodeType);
}
for (int i = 1; i < sr.Depth; i++)
Console.Write(" ");
Console.Write(sr.NodeType.ToString() + " " + sr.Name);
if (sr.NodeType == XmlNodeType.Element && sr.AttributeCount > 0) {
sr.MoveToAttribute(0);
Console.Write(" (" + sr.Name+"="+sr.Value + ")");
sr.MoveToElement();
}
if (sr.Value != null) {
Console.Write(" " + sr.Value.Replace("\n"," ").Replace("\r",""));
}
Console.WriteLine();
}
}
示例2: ConvertCommentToMarkdown
private static string ConvertCommentToMarkdown(string body)
{
var sb = new StringBuilder();
var sgmlReader = new SgmlReader
{
InputStream = new StringReader(body),
DocType = "HTML",
WhitespaceHandling = WhitespaceHandling.Significant,
CaseFolding = CaseFolding.ToLower
};
bool outputEndElement = false;
int indentLevel = 0;
while (sgmlReader.Read())
{
switch (sgmlReader.NodeType)
{
case XmlNodeType.Text:
if (indentLevel > 0)
sb.Append("\t");
sb.AppendLine(sgmlReader.Value);
break;
case XmlNodeType.Element:
switch (sgmlReader.LocalName)
{
case "h1":
sb.Append("## ");
break;
case "br":
sb.AppendLine(" ");
break;
case "a":
if (sgmlReader.MoveToAttribute("href"))
{
string url = sgmlReader.Value;
sgmlReader.Read();
sb.AppendFormat("[{0}]({1})", sgmlReader.Value, url);
}
break;
case "html":
break;
case "strong":
case "b":
sb.AppendFormat("**{0}**", sgmlReader.Value);
break;
case "i":
case "em":
sb.AppendFormat("_{0}_", sgmlReader.Value);
break;
case "li":
sb.AppendFormat("- {0}", sgmlReader.Value);
break;
case "pre":
case "code":
case "quote":
indentLevel = 1;
break;
case "ul":
case "ol":
case "img":
break;
default:
outputEndElement = true;
sb.Append("<").Append(sgmlReader.LocalName);
break;
}
break;
case XmlNodeType.SignificantWhitespace:
case XmlNodeType.Whitespace:
case XmlNodeType.CDATA:
break;
case XmlNodeType.EndElement:
indentLevel = 0;
if (outputEndElement)
sb.Append(">");
outputEndElement = false;
break;
default:
throw new ArgumentOutOfRangeException();
}
}
return sb.ToString();
}