クラスが、現在のコンテキストまたは位置から XmlNode を返せるようにします。
この型のすべてのメンバの一覧については、IHasXmlNode メンバ を参照してください。
Public Interface IHasXmlNode
[C#]
public interface IHasXmlNode
[C++]
public __gc __interface IHasXmlNode
[JScript]
public interface IHasXmlNode
解説
IHasXmlNode インターフェイスは、クラスが現在のコンテキストまたは位置から XmlNode を返せるようにするインターフェイスを提供します。このインターフェイスは、 XmlNode ノードのあるクラス上で動作する XPathNavigator オブジェクトによって実装されます。たとえば、 XPathNavigator オブジェクトが XmlDocument によって作成される場合は、 GetNode メソッドを使用して、ナビゲータの現在位置を表す XmlNode を返すことができます。
使用例
[Visual Basic, C#, C++] GetNode メソッドを使用して、選択されたノードを取得し、変更する例を次に示します。
Imports System
Imports System.IO
Imports System.Xml
Imports System.Xml.XPath
public class Sample
public shared sub Main()
Dim doc as XmlDocument = new XmlDocument()
doc.Load("books.xml")
' Create an XPathNavigator and select all books by Plato.
Dim nav as XPathNavigator = doc.CreateNavigator()
Dim ni as XPathNodeIterator = nav.Select("descendant::book[author/name='Plato']")
ni.MoveNext()
' Get the first matching node and change the book price.
Dim book as XmlNode = CType(ni.Current, IHasXmlNode).GetNode()
book.LastChild.InnerText = "12.95"
Console.WriteLine(book.OuterXml)
end sub
end class
[C#]
using System;
using System.IO;
using System.Xml;
using System.Xml.XPath;
public class Sample
{
public static void Main()
{
XmlDocument doc = new XmlDocument();
doc.Load("books.xml");
// Create an XPathNavigator and select all books by Plato.
XPathNavigator nav = doc.CreateNavigator();
XPathNodeIterator ni = nav.Select("descendant::book[author/name='Plato']");
ni.MoveNext();
// Get the first matching node and change the book price.
XmlNode book = ((IHasXmlNode)ni.Current).GetNode();
book.LastChild.InnerText = "12.95";
Console.WriteLine(book.OuterXml);
}
}
[C++]
#using <mscorlib.dll>
#using <System.Xml.dll>
using namespace System;
using namespace System::IO;
using namespace System::Xml;
using namespace System::Xml::XPath;
int main() {
XmlDocument* doc = new XmlDocument();
doc -> Load(S"books.xml");
// Create an XPathNavigator and select all books by Plato.
XPathNavigator * nav = doc -> CreateNavigator();
XPathNodeIterator * ni = nav -> Select(S"descendant::book[author/name='Plato']");
ni -> MoveNext();
// Get the first matching node and change the book price.
XmlNode * book = dynamic_cast<IHasXmlNode*>(ni -> Current)->GetNode();
book -> LastChild -> InnerText = S"12.95";
Console::WriteLine(book -> OuterXml);
}
この例では、入力として、 books.xml というファイルを使用しています。
<bookstore>
<book genre="autobiography" publicationdate="1981" ISBN="1-861003-11-0">
<title>The Autobiography of Benjamin Franklin</title>
<author>
<first-name>Benjamin</first-name>
<last-name>Franklin</last-name>
</author>
<price>8.99</price>
</book>
<book genre="novel" publicationdate="1967" ISBN="0-201-63361-2">
<title>The Confidence Man</title>
<author>
<first-name>Herman</first-name>
<last-name>Melville</last-name>
</author>
<price>11.99</price>
</book>
<book genre="philosophy" publicationdate="1991" ISBN="1-861001-57-6">
<title>The Gorgias</title>
<author>
<name>Plato</name>
</author>
<price>9.99</price>
</book>
</bookstore>
[JScript] JScript のサンプルはありません。Visual Basic、C#、および C++ のサンプルを表示するには、このページの左上隅にある言語のフィルタ ボタン をクリックします。
必要条件
名前空間: System.Xml
プラットフォーム: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 ファミリ
アセンブリ: System.Xml (System.Xml.dll 内)