XmlAttribute.Value 屬性
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
取得或設定節點的值。
public:
virtual property System::String ^ Value { System::String ^ get(); void set(System::String ^ value); };
public override string Value { get; set; }
member this.Value : string with get, set
Public Overrides Property Value As String
屬性值
傳回值需視節點的 NodeType 而定。 至於 XmlAttribute
節點,這個屬性 (Property) 是屬性 (Attribute) 的值。
例外狀況
節點為唯讀,並會呼叫設定作業。
範例
下列範例會顯示內容集合中每個節點的資訊。
#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