System.Xml.IXmlLineInfo 接口

方法描述

提供一个接口,使类可以返回行和位置信息。

语法定义(C# System.Xml.IXmlLineInfo 接口 的用法)

public interface IXmlLineInfo

构造函数

构造函数名称 构造函数描述

成员/方法

方法名称 方法描述
HasLineInfo 获取一个值,该值指示该类是否可返回行信息。

提示和注释

System.Xml.IXmlLineInfo 接口例子

显示每个节点,包括其深度、行号和行位置。

using System;
using System.IO;
using System.Xml;

public class Sample{

  public static void Main(){

    // Create the XML fragment to be parsed.
    string xmlFrag  = 
    @"
           
              
              240
           
        
    ";

    // 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("", reader.Name);
           break;
       }       
     }           
    }

    // Close the reader.
    reader.Close();       
  }
}

继承层次结构

命名空间

namespace: System.Xml

程序集: System.Xml(在 System.Xml.dll 中)

线程安全

版本信息

.NET Framework 受以下版本支持:4、3.5、3.0、2.0、1.1、1.0 .NET Framework Client Profile 受以下版本支持:4、3.5 SP1 受以下版本支持:

适用平台

Windows 7, Windows Vista SP1 或更高版本, Windows XP SP3, Windows XP SP2 x64 Edition, Windows Server 2008(不支持服务器核心), Windows Server 2008 R2(支持 SP1 或更高版本的服务器核心), Windows Server 2003 SP2 .NET Framework 并不是对每个平台的所有版本都提供支持。有关支持的版本的列表,请参见.NET Framework 系统要求。