次の方法で共有


XmlAttribute.BaseURI プロパティ

ノードのベース URI を取得します。

Overrides Public ReadOnly Property BaseURI As String
[C#]
public override string BaseURI {get;}
[C++]
public: __property String* get_BaseURI();
[JScript]
public override function get BaseURI() : String;

プロパティ値

ノードの読み込み元の場所。ノードにベース URI がない場合は String.Empty。属性ノードのベース URI は、その所有者要素と同じです。属性ノードに所有者要素がない場合、 BaseURI は String.Empty を返します。

解説

ネットワーク化した XML ドキュメントは、さまざまな W3C 標準包含機構を使用して集約されたデータのチャンクで構成されるため、異なる場所からのノードを含んでいます。 BaseURI プロパティは、ノードが存在していた元の位置を通知します。

BaseURI に関する追加情報と、他のノード型でどのように動作するかの詳細については、 XmlNode.BaseURI のトピックを参照してください。

このプロパティは、ドキュメント オブジェクト モデル (DOM: Document Object Model) に対する Microsoft 拡張機能です。

使用例

[Visual Basic, C#, C++] 属性ノードの情報をそのベース URI も含めて表示する例を次に示します。

 
Option Explicit
Option Strict

Imports System
Imports System.IO
Imports System.Xml

Public Class Sample
    
    Public Shared Sub Main()
        'Create the XmlDocument.
        Dim doc As New XmlDocument()
        doc.Load("https://localhost/baseuri.xml")
        
        'Display information on the attribute node. The value
        'returned for BaseURI is 'https://localhost/baseuri.xml'.
        Dim attr As XmlAttribute = doc.DocumentElement.Attributes(0)
        Console.WriteLine("Name of the attribute:  {0}", attr.Name)
        Console.WriteLine("Base URI of the attribute:  {0}", attr.BaseURI)
        Console.WriteLine("The value of the attribute:  {0}", attr.InnerText)
    End Sub 'Main 
End Class 'Sample

[C#] 
using System;
using System.IO;
using System.Xml;

public class Sample
{
  public static void Main()
  {
    //Create the XmlDocument.
    XmlDocument doc = new XmlDocument();
    doc.Load("https://localhost/baseuri.xml");
                     
    //Display information on the attribute node. The value
    //returned for BaseURI is 'https://localhost/baseuri.xml'.
    XmlAttribute attr = doc.DocumentElement.Attributes[0];
    Console.WriteLine("Name of the attribute:  {0}", attr.Name);
    Console.WriteLine("Base URI of the attribute:  {0}", attr.BaseURI);
    Console.WriteLine("The value of the attribute:  {0}", attr.InnerText);

  }
}

[C++] 
#using <mscorlib.dll>
#using <System.Xml.dll>
using namespace System;
using namespace System::IO;
using namespace System::Xml;

int main()
{
    //Create the XmlDocument.
    XmlDocument* doc = new XmlDocument();
    doc->Load(S"https://localhost/baseuri.xml");
                     
    //Display information on the attribute node. The value
    //returned for BaseURI is 'https://localhost/baseuri.xml'.
    XmlAttribute* attr = doc->DocumentElement->Attributes->ItemOf[0];
    Console::WriteLine(S"Name of the attribute:  {0}",attr->Name);
    Console::WriteLine(S"Base URI of the attribute:  {0}",attr->BaseURI);
    Console::WriteLine(S"The value of the attribute:  {0}",attr->InnerText);

}

[Visual Basic, C#, C++] このサンプルでは、入力として、 baseuri.xml というファイルを使用しています。

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

[JScript] JScript のサンプルはありません。Visual Basic、C#、および C++ のサンプルを表示するには、このページの左上隅にある言語のフィルタ ボタン 言語のフィルタ をクリックします。

必要条件

プラットフォーム: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 ファミリ, .NET Compact Framework - Windows CE .NET

参照

XmlAttribute クラス | XmlAttribute メンバ | System.Xml 名前空間 | OwnerElement