Hinweis
Für den Zugriff auf diese Seite ist eine Autorisierung erforderlich. Sie können versuchen, sich anzumelden oder das Verzeichnis zu wechseln.
Für den Zugriff auf diese Seite ist eine Autorisierung erforderlich. Sie können versuchen, das Verzeichnis zu wechseln.
Fügt einen XmlNode unter Verwendung der entsprechenden Name-Eigenschaft hinzu.
Namespace: System.Xml
Assembly: System.Xml (in system.xml.dll)
Syntax
'Declaration
Public Overridable Function SetNamedItem ( _
node As XmlNode _
) As XmlNode
'Usage
Dim instance As XmlNamedNodeMap
Dim node As XmlNode
Dim returnValue As XmlNode
returnValue = instance.SetNamedItem(node)
public virtual XmlNode SetNamedItem (
XmlNode node
)
public:
virtual XmlNode^ SetNamedItem (
XmlNode^ node
)
public XmlNode SetNamedItem (
XmlNode node
)
public function SetNamedItem (
node : XmlNode
) : XmlNode
Parameter
- node
Ein in der XmlNamedNodeMap zu speichernder XmlNode. Wenn ein Knoten mit diesem Namen bereits in der Zuordnung enthalten ist, wird er durch den neuen ersetzt.
Rückgabewert
Wenn der node einen vorhandenen Knoten mit demselben Namen ersetzt, wird der alte Knoten zurückgegeben, andernfalls wird NULL (Nothing in Visual Basic) zurückgegeben.
Ausnahmen
| Ausnahmetyp | Bedingung |
|---|---|
Der node wurde aus einem anderen XmlDocument als dem erstellt, das die XmlNamedNodeMap erstellt hat; oder die XmlNamedNodeMap ist schreibgeschützt. |
Beispiel
Im folgenden Beispiel wird mit der XmlAttributeCollection-Klasse (die von XmlNamedNodeMap erbt) der Auflistung ein Attribut hinzugefügt.
Imports System
Imports System.IO
Imports System.Xml
public class Sample
public shared sub Main()
Dim doc as XmlDocument = new XmlDocument()
doc.LoadXml("<book genre='novel' publicationdate='1997'> " & _
" <title>Pride And Prejudice</title>" & _
"</book>")
Dim attrColl as XmlAttributeCollection = doc.DocumentElement.Attributes
' Add a new attribute to the collection.
Dim attr as XmlAttribute = doc.CreateAttribute("style")
attr.Value = "hardcover"
attrColl.SetNamedItem(attr)
Console.WriteLine("Display the modified XML...")
Console.WriteLine(doc.OuterXml)
end sub
end class
using System;
using System.IO;
using System.Xml;
public class Sample
{
public static void Main()
{
XmlDocument doc = new XmlDocument();
doc.LoadXml("<book genre='novel' publicationdate='1997'> " +
" <title>Pride And Prejudice</title>" +
"</book>");
XmlAttributeCollection attrColl = doc.DocumentElement.Attributes;
// Add a new attribute to the collection.
XmlAttribute attr = doc.CreateAttribute("style");
attr.Value = "hardcover";
attrColl.SetNamedItem(attr);
Console.WriteLine("Display the modified XML...");
Console.WriteLine(doc.OuterXml);
}
}
#using <System.Xml.dll>
using namespace System;
using namespace System::IO;
using namespace System::Xml;
int main()
{
XmlDocument^ doc = gcnew XmlDocument;
doc->LoadXml( "<book genre='novel' publicationdate='1997'> <title>Pride And Prejudice</title></book>" );
XmlAttributeCollection^ attrColl = doc->DocumentElement->Attributes;
// Add a new attribute to the collection.
XmlAttribute^ attr = doc->CreateAttribute( "style" );
attr->Value = "hardcover";
attrColl->SetNamedItem( attr );
Console::WriteLine( "Display the modified XML..." );
Console::WriteLine( doc->OuterXml );
}
import System.*;
import System.IO.*;
import System.Xml.*;
public class Sample
{
public static void main(String[] args)
{
XmlDocument doc = new XmlDocument();
doc.LoadXml("<book genre='novel' publicationdate='1997'> "
+ " <title>Pride And Prejudice</title>"
+ "</book>");
XmlAttributeCollection attrColl =
doc.get_DocumentElement().get_Attributes();
// Add a new attribute to the collection.
XmlAttribute attr = doc.CreateAttribute("style");
attr.set_Value("hardcover");
attrColl.SetNamedItem(attr);
Console.WriteLine("Display the modified XML...");
Console.WriteLine(doc.get_OuterXml());
} //main
} //Sample
Plattformen
Windows 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile für Pocket PC, Windows Mobile für Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
.NET Framework unterstützt nicht alle Versionen sämtlicher Plattformen. Eine Liste der unterstützten Versionen finden Sie unter Systemanforderungen.
Versionsinformationen
.NET Framework
Unterstützt in: 2.0, 1.1, 1.0
.NET Compact Framework
Unterstützt in: 2.0, 1.0
Siehe auch
Referenz
XmlNamedNodeMap-Klasse
XmlNamedNodeMap-Member
System.Xml-Namespace