XmlNamedNodeMap.GetNamedItem 方法
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
从节点集合中XmlNode检索指定的XmlNamedNodeMap值。
重载
| 名称 | 说明 |
|---|---|
| GetNamedItem(String) |
XmlNode检索按名称指定的名称。 |
| GetNamedItem(String, String) |
检索具有匹配 LocalName 项和 NamespaceURI. 的节点。 |
GetNamedItem(String)
- Source:
- XmlNamedNodemap.cs
- Source:
- XmlNamedNodemap.cs
- Source:
- XmlNamedNodemap.cs
- Source:
- XmlNamedNodemap.cs
- Source:
- XmlNamedNodemap.cs
XmlNode检索按名称指定的名称。
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
参数
返回
XmlNode具有指定名称或null找不到匹配的节点。
示例
以下示例使用 XmlAttributeCollection 类(继承自 XmlNamedNodeMap该类)来修改属性。
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
适用于
GetNamedItem(String, String)
- Source:
- XmlNamedNodemap.cs
- Source:
- XmlNamedNodemap.cs
- Source:
- XmlNamedNodemap.cs
- Source:
- XmlNamedNodemap.cs
- Source:
- XmlNamedNodemap.cs
检索具有匹配 LocalName 项和 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
参数
- localName
- String
要检索的节点的本地名称。
- namespaceURI
- String
要检索的节点的命名空间统一资源标识符(URI)。
返回
XmlNode具有匹配的本地名称和命名空间 URI,或者null找不到匹配的节点。