XmlTextReader.NamespaceURI 属性
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
获取读取器定位在的节点的命名空间 URI(采用 W3C 命名空间规范中定义)。
public:
virtual property System::String ^ NamespaceURI { System::String ^ get(); };
public override string NamespaceURI { get; }
member this.NamespaceURI : string
Public Overrides ReadOnly Property NamespaceURI As String
属性值
当前节点的命名空间 URI;否则为空字符串。
示例
以下示例显示每个节点的本地名称,以及前缀和命名空间 URI(如果存在)。
#using <System.Xml.dll>
using namespace System;
using namespace System::IO;
using namespace System::Xml;
int main()
{
XmlTextReader^ reader = nullptr;
try
{
// Load the reader with the XML file.
reader = gcnew XmlTextReader( "book2.xml" );
// Parse the file. If they exist, display the prefix and
// namespace URI of each node.
while ( reader->Read() )
{
if ( reader->IsStartElement() )
{
if ( reader->Prefix == String::Empty )
Console::WriteLine( "<{0}>", reader->LocalName );
else
{
Console::Write( "<{0}:{1}>", reader->Prefix, reader->LocalName );
Console::WriteLine( " The namespace URI is {0}", reader->NamespaceURI );
}
}
}
}
finally
{
if ( reader != nullptr )
reader->Close();
}
}
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("book2.xml");
// Parse the file. If they exist, display the prefix and
// namespace URI of each node.
while (reader.Read()) {
if (reader.IsStartElement()) {
if (reader.Prefix==String.Empty)
{
Console.WriteLine("<{0}>", reader.LocalName);
}
else {
Console.Write("<{0}:{1}>", reader.Prefix, reader.LocalName);
Console.WriteLine(" The namespace URI is " + reader.NamespaceURI);
}
}
}
}
finally {
if (reader != null)
reader.Close();
}
}
} // End class
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("book2.xml")
' Parse the file. If they exist, display the prefix and
' namespace URI of each node.
While reader.Read()
If reader.IsStartElement() Then
If reader.Prefix = String.Empty Then
Console.WriteLine("<{0}>", reader.LocalName)
Else
Console.Write("<{0}:{1}>", reader.Prefix, reader.LocalName)
Console.WriteLine(" The namespace URI is " & reader.NamespaceURI)
End If
End If
End While
Finally
If Not (reader Is Nothing) Then
reader.Close()
End If
End Try
End Sub
End Class
该示例使用 文件 book2.xml
作为输入。
<book xmlns:bk='urn:samples'>
<title>Pride And Prejudice</title>
<bk:genre>novel</bk:genre>
</book>
注解
注意
从 .NET Framework 2.0 开始,建议使用 XmlReader.Create 方法创建XmlReader实例,以利用新功能。
此属性仅与 Element
和 Attribute
节点相关。