このノードの名前空間プリフィックスを取得または設定します。
Overrides Public Property Prefix As String
[C#]
public override string Prefix {get; set;}
[C++]
public: __property String* get_Prefix();public: __property void set_Prefix(String*);
[JScript]
public override function get Prefix() : String;public override function set Prefix(String);
プロパティ値
このノードの名前空間プリフィックス。プリフィックスがない場合、このプロパティは String.Empty を返します。
例外
例外の種類 | 条件 |
---|---|
ArgumentException | このノードは読み取り専用です。 |
XmlException | 指定したプリフィックスに無効な文字が含まれています。
指定されたプリフィックスの書式が正しくありません。 このノードの namespaceURI が null 参照 (Visual Basic では Nothing) です。 指定したプリフィックスが "xml" であり、このノードの namespaceURI が "http://www.w3.org/XML/1998/namespace" と異なっています。 このノードが属性で、指定したプリフィックスが "xmlns" で、このノードの namespaceURI が "http://www.w3.org/2000/xmlns/ " と異なります。 このノードが属性で、このノードの qualifiedName が "xmlns" [Namespaces] です。 |
解説
属性のプリフィックスを変更しても名前空間 URI は変更されないため、既定値があることが判明している属性のプリフィックスを変更しても、その既定値および元のプリフィックスを持った新しい属性は作成されません。
使用例
[Visual Basic, C#, C++] 属性コレクションの各ノードに関する情報を表示する例を次に示します。
Imports System
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
[C#]
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);
}
}
}
[C++]
#using <mscorlib.dll>
#using <System.Xml.dll>
using namespace System;
using namespace System::IO;
using namespace System::Xml;
int main()
{
XmlDocument* doc = new XmlDocument();
doc->LoadXml(S"<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(S"Display information on each of the attributes... \r\n");
System::Collections::IEnumerator* myEnum = attrColl->GetEnumerator();
while (myEnum->MoveNext())
{
XmlAttribute* attr = __try_cast<XmlAttribute*>(myEnum->Current);
Console::Write(S"{0}:{1} = {2}",attr->Prefix,attr->LocalName,attr->Value);
Console::WriteLine(S"\t namespaceURI={0}", attr->NamespaceURI);
}
}
[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