XmlNamedNodeMap.GetNamedItem Method
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.
Retrieves the specified XmlNode from the collection of nodes in the XmlNamedNodeMap.
GetNamedItem(String) |
Retrieves an XmlNode specified by name. |
GetNamedItem(String, String) |
Retrieves a node with the matching LocalName and NamespaceURI. |
- Source:
- XmlNamedNodemap.cs
- Source:
- XmlNamedNodemap.cs
- Source:
- XmlNamedNodemap.cs
Retrieves an XmlNode specified by name.
public:
virtual System::Xml::XmlNode ^ GetNamedItem(System::String ^ name);
public virtual System.Xml.XmlNode GetNamedItem (string name);
public virtual System.Xml.XmlNode? GetNamedItem (string name);
abstract member GetNamedItem : string -> System.Xml.XmlNode
override this.GetNamedItem : string -> System.Xml.XmlNode
Public Overridable Function GetNamedItem (name As String) As XmlNode
Parameters
- name
- String
The qualified name of the node to retrieve. It is matched against the Name property of the matching node.
Returns
An XmlNode
with the specified name or null
if a matching node is not found.
Examples
The following example uses the XmlAttributeCollection class (which inherits from XmlNamedNodeMap
) to modify an 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 genre='novel' publicationdate='1997'> <title>Pride And Prejudice</title></book>" );
XmlAttributeCollection^ attrColl = doc->DocumentElement->Attributes;
// Change the value for the genre attribute.
XmlAttribute^ attr = dynamic_cast<XmlAttribute^>(attrColl->GetNamedItem( "genre" ));
attr->Value = "fiction";
Console::WriteLine( "Display the modified XML..." );
Console::WriteLine( doc->OuterXml );
}
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;
// Change the value for the genre attribute.
XmlAttribute attr = (XmlAttribute)attrColl.GetNamedItem("genre");
attr.Value = "fiction";
Console.WriteLine("Display the modified XML...");
Console.WriteLine(doc.OuterXml);
}
}
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
' Change the value for the genre attribute.
Dim attr as XmlAttribute = CType(attrColl.GetNamedItem("genre"),XmlAttribute)
attr.Value = "fiction"
Console.WriteLine("Display the modified XML...")
Console.WriteLine(doc.OuterXml)
end sub
end class
Applies to
.NET 9 και άλλες εκδόσεις
Προϊόν | Εκδόσεις |
---|---|
.NET | Core 1.0, Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9 |
.NET Framework | 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1 |
.NET Standard | 2.0, 2.1 |
UWP | 10.0 |
- Source:
- XmlNamedNodemap.cs
- Source:
- XmlNamedNodemap.cs
- Source:
- XmlNamedNodemap.cs
Retrieves a node with the matching LocalName and NamespaceURI.
public:
virtual System::Xml::XmlNode ^ GetNamedItem(System::String ^ localName, System::String ^ namespaceURI);
public virtual System.Xml.XmlNode GetNamedItem (string localName, string namespaceURI);
public virtual System.Xml.XmlNode? GetNamedItem (string localName, string? namespaceURI);
abstract member GetNamedItem : string * string -> System.Xml.XmlNode
override this.GetNamedItem : string * string -> System.Xml.XmlNode
Public Overridable Function GetNamedItem (localName As String, namespaceURI As String) As XmlNode
Parameters
- localName
- String
The local name of the node to retrieve.
- namespaceURI
- String
The namespace Uniform Resource Identifier (URI) of the node to retrieve.
Returns
An XmlNode with the matching local name and namespace URI or null
if a matching node was not found.
Applies to
.NET 9 και άλλες εκδόσεις
Προϊόν | Εκδόσεις |
---|---|
.NET | Core 1.0, Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9 |
.NET Framework | 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1 |
.NET Standard | 2.0, 2.1 |
UWP | 10.0 |
.NET σχόλια
.NET είναι ένα έργο ανοιχτού κώδικα. Επιλέξτε μια σύνδεση για να παρέχετε σχόλια: