本文整理匯總了C#中Sgml.SgmlReader.MoveToElement方法的典型用法代碼示例。如果您正苦於以下問題:C# SgmlReader.MoveToElement方法的具體用法?C# SgmlReader.MoveToElement怎麽用?C# SgmlReader.MoveToElement使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Sgml.SgmlReader
的用法示例。
在下文中一共展示了SgmlReader.MoveToElement方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。
示例1: 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());
}
}
}
示例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: 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();
}
}