XmlTextReader.BaseURI 属性

定义

获取当前节点的基 URI。

public:
 virtual property System::String ^ BaseURI { System::String ^ get(); };
public override string BaseURI { get; }
public override string? BaseURI { get; }
member this.BaseURI : string
Public Overrides ReadOnly Property BaseURI As String

属性值

当前节点的基 URI。

示例

以下示例显示每个节点的基 URI。

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

public class Sample
{
  public static void Main()
  {
    XmlTextReader reader = null;

    try
    {
        //Load the reader with the XML file.
        reader = new XmlTextReader("http://localhost/baseuri.xml");

        //Parse the file and display the base URI for each node.
        while (reader.Read())
        {
            Console.WriteLine("({0}) {1}", reader.NodeType, reader.BaseURI);
         }
     }

     finally
     {
       if (reader!=null)
         reader.Close();
     }
  }
} // End class
Option Explicit
Option Strict

Imports System.IO
Imports System.Xml

Public Class Sample
   
   Public Shared Sub Main()
      Dim reader As XmlTextReader = Nothing
      
      Try
         'Load the reader with the XML file.
         reader = New XmlTextReader("http://localhost/baseuri.xml")
         
         'Parse the file and display the base URI for each node.
         While reader.Read()
            Console.WriteLine("({0}) {1}", reader.NodeType, reader.BaseURI)
         End While
      
      Finally
         If Not (reader Is Nothing) Then
            reader.Close()
         End If
      End Try
   End Sub
End Class

该示例使用该文件 baseuri.xml作为输入。


<!-- XML fragment -->
<book genre="novel">
  <title>Pride And Prejudice</title>
</book>

注解

注释

建议您使用XmlReader方法创建XmlReader.Create实例,以利用新功能。

网络 XML 文档由使用各种 W3C 标准包含机制聚合的数据区块组成,因此包含来自不同位置的节点。 DTD 实体是一个示例,但这不限于 DTD。 基本 URI 会告知这些节点来自何处。 如果返回的节点没有基 URI(例如,从内存中字符串分析它们), String.Empty 则返回。

适用于

另请参阅