XmlValidatingReader.BaseURI Property

Gets the base URI of the current node.

Namespace: System.Xml
Assembly: System.Xml (in system.xml.dll)

public override string BaseURI { get; }
/** @property */
public String get_BaseURI ()

public override function get BaseURI () : String

Not applicable.

Property Value

The base URI of the current node.

NoteNote:

The XmlValidatingReader class is obsolete in Microsoft .NET Framework version 2.0. You can create a validating XmlReader instance by using the XmlReaderSettings class and the Create method. For more information, see Validating XML Data with XmlReader.

A networked XML document is comprised of chunks of data aggregated by using various World Wide Web Consortium (W3C) standard inclusion mechanisms and therefore contains nodes that come from different places. document type definition (DTD) entities are an example of this, but this is not limited to DTDs. The base URI tells you where these nodes came from. If there is no base URI for the nodes being returned (for example, they were parsed from an in-memory string), String.Empty is returned.

The following example parses a file and displays the base URI of each node.

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

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

    try
    {           
        //Create the validating reader.
        txtreader = new XmlTextReader("http://localhost/uri.xml");
        reader = new XmlValidatingReader(txtreader);
        reader.ValidationType = ValidationType.None;

        //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

import System.*;
import System.IO.*;
import System.Xml.*;

public class Sample
{
    public static void main(String[] args)
    {
        XmlValidatingReader reader = null;
        XmlTextReader txtReader = null;
        try {        
            //Create the validating reader.
            txtReader = new XmlTextReader("http://localhost/uri.xml");
            reader = new XmlValidatingReader(txtReader);
            reader.set_ValidationType(ValidationType.None);

            //Parse the file and display the base URI for each node.
            while (reader.Read()) {            
                Console.WriteLine("({0}) {1}", reader.get_NodeType(), 
                    reader.get_BaseURI());
            }
        }
        finally {
            if (reader != null) {
                reader.Close();
            }
        }
    } //main
}// End class Sample

The example uses the file, uri.xml, as input.


<!-- XML fragment -->
<!DOCTYPE book [<!ENTITY s SYSTEM "tmp/style.xml">]>
<book genre="novel">
  <title>Pride And Prejudice</title>
  <misc>&s;</misc>
</book>

The style.xml file contains the XML text <style>hardcover</style>.

Windows 98, Windows Server 2000 SP4, Windows Millennium Edition, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.

.NET Framework

Supported in: 3.0, 2.0, 1.1, 1.0
Show: