사용한 XML 문서는 이전 글을 참조하기 바란다.
using System;
using System.Linq;
using System.Collections.Generic;
using System.Text;using System.Xml.XPath;
namespace CH11
{
class p566_XPathNavagator
{
static void Main()
{
string filePath = @"..\..\booklist.xml";
XPathDocument xPathDoc = new XPathDocument(filePath);
XPathNavigator xPathNavi = xPathDoc.CreateNavigator();// XPath 반복기
XPathNodeIterator xPathNodeIterator = xPathNavi.Select(
"//booklist/book/title[../@kind='컴퓨터']");while (xPathNodeIterator.MoveNext())
{
XPathNavigator naviTitle = xPathNodeIterator.Current;
Console.WriteLine(naviTitle.Value);
}
}
}
}