本文整理汇总了C#中System.Xml.IXmlLineInfo接口的典型用法代码示例。如果您正苦于以下问题:C# IXmlLineInfo接口的具体用法?C# IXmlLineInfo怎么用?C# IXmlLineInfo使用的例子?那么恭喜您, 这里精选的接口代码示例或许可以为您提供帮助。
IXmlLineInfo接口属于System.Xml命名空间,在下文中一共展示了IXmlLineInfo接口的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Main
//引入命名空间
using System;
using System.IO;
using System.Xml;
public class Sample{
public static void Main(){
// Create the XML fragment to be parsed.
string xmlFrag =
@"<book>
<misc>
<style>paperback</style>
<pages>240</pages>
</misc>
</book>
";
// Create the XmlNamespaceManager.
XmlNamespaceManager nsmgr = new XmlNamespaceManager(new NameTable());
// Create the XmlParserContext.
XmlParserContext context = new XmlParserContext(null, nsmgr, null, XmlSpace.None);
// Create the reader.
XmlValidatingReader reader = new XmlValidatingReader(xmlFrag, XmlNodeType.Element, context);
IXmlLineInfo lineInfo = ((IXmlLineInfo)reader);
if (lineInfo.HasLineInfo()){
// Parse the XML and display each node.
while (reader.Read()){
switch (reader.NodeType){
case XmlNodeType.Element:
Console.Write("{0} {1},{2} ", reader.Depth, lineInfo.LineNumber, lineInfo.LinePosition);
Console.WriteLine("<{0}>", reader.Name);
break;
case XmlNodeType.Text:
Console.Write("{0} {1},{2} ", reader.Depth, lineInfo.LineNumber, lineInfo.LinePosition);
Console.WriteLine(" {0}", reader.Value);
break;
case XmlNodeType.EndElement:
Console.Write("{0} {1},{2} ", reader.Depth, lineInfo.LineNumber, lineInfo.LinePosition);
Console.WriteLine("</{0}>", reader.Name);
break;
}
}
}
// Close the reader.
reader.Close();
}
}