XmlAttribute::Prefix Property
Gets or sets the namespace prefix of this node.
Assembly: System.Xml (in System.Xml.dll)
public: property String^ Prefix { virtual String^ get() override; virtual void set(String^ value) override; }
Property Value
Type: System::String^The namespace prefix of this node. If there is no prefix, this property returns String.Empty.
| Exception | Condition |
|---|---|
| ArgumentException | This node is read-only. |
| XmlException | The specified prefix contains an invalid character. The specified prefix is malformed. The namespaceURI of this node is null. The specified prefix is "xml", and the namespaceURI of this node is different from "http://www.w3.org/XML/1998/namespace". This node is an attribute, the specified prefix is "xmlns", and the namespaceURI of this node is different from "http://www.w3.org/2000/xmlns/". This node is an attribute, and the qualifiedName of this node is "xmlns" [Namespaces]. |
Because changing the prefix of an attribute does not change its namespace URI, changing the prefix of an attribute that is known to have a default value does not create a new attribute with the default value and the original prefix.
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 ); } }
Available since 10
.NET Framework
Available since 1.1