XmlAttribute.NamespaceURI Property
Definition
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
Gets the namespace URI of this node.
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
Property Value
The namespace URI of this node. If the attribute is not explicitly given a namespace, this property returns String.Empty.
Examples
The following example displays information on each of the nodes in the attribute collection.
#using <System.Xml.dll>
using namespace System;
using namespace System::IO;
using namespace System::Xml;
int main()
{
XmlDocument^ doc = gcnew XmlDocument;
doc->LoadXml( "<book xmlns:bk='urn:samples' bk:genre='novel'><title>Pride And Prejudice</title></book>" );
//Create an attribute collection.
XmlAttributeCollection^ attrColl = doc->DocumentElement->Attributes;
Console::WriteLine( "Display information on each of the attributes... \r\n" );
System::Collections::IEnumerator^ myEnum = attrColl->GetEnumerator();
while ( myEnum->MoveNext() )
{
XmlAttribute^ attr = safe_cast<XmlAttribute^>(myEnum->Current);
Console::Write( "{0}:{1} = {2}", attr->Prefix, attr->LocalName, attr->Value );
Console::WriteLine( "\t namespaceURI={0}", attr->NamespaceURI );
}
}
using System;
using System.IO;
using System.Xml;
public class Sample
{
public static void Main(){
XmlDocument doc = new XmlDocument();
doc.LoadXml("<book xmlns:bk='urn:samples' bk:genre='novel'>" +
"<title>Pride And Prejudice</title>" +
"</book>");
//Create an attribute collection.
XmlAttributeCollection attrColl = doc.DocumentElement.Attributes;
Console.WriteLine("Display information on each of the attributes... \r\n");
foreach (XmlAttribute attr in attrColl){
Console.Write("{0}:{1} = {2}", attr.Prefix, attr.LocalName, attr.Value);
Console.WriteLine("\t namespaceURI=" + attr.NamespaceURI);
}
}
}
Imports System.IO
Imports System.Xml
public class Sample
public shared sub Main()
Dim doc as XmlDocument = new XmlDocument()
doc.LoadXml("<book xmlns:bk='urn:samples' bk:genre='novel'>" & _
"<title>Pride And Prejudice</title>" & _
"</book>")
'Create an attribute collection.
Dim attrColl as XmlAttributeCollection = doc.DocumentElement.Attributes
Console.WriteLine("Display information on each of the attributes... ")
Dim attr as XmlAttribute
for each attr in attrColl
Console.Write("{0}:{1} = {2}", attr.Prefix, attr.LocalName, attr.Value)
Console.WriteLine(" namespaceURI=" + attr.NamespaceURI)
next
end sub
end class
Remarks
An attribute does not inherit its namespace from the element it is attached to. If an attribute is not explicitly given a namespace, the namespace URI is considered to be String.Empty.
Applies to
GitHub에서 Microsoft와 공동 작업
이 콘텐츠의 원본은 GitHub에서 찾을 수 있으며, 여기서 문제와 끌어오기 요청을 만들고 검토할 수도 있습니다. 자세한 내용은 참여자 가이드를 참조하세요.
.NET