Home
Register
About
Login
Categories
C#
(13)
VB.NET
(0)
F#
(0)
ASP.NET
(15)
JavaScript
(4)
C++
(0)
C
(0)
Python
(0)
Ruby
(0)
Rails
(0)
J#
(0)
SQL
(0)
VB Script
(0)
HTML
(0)
CSS
(2)
XML
(2)
XSLT
(0)
Unit Testing
(7)
Architecture
(2)
Ajax
(0)
Project Management
(0)
LINQ to SQL
(2)
LINQ
(0)
LINQ to XML
(1)
NHibernate
(0)
Active Record
(0)
Silverlight
(0)
ASP.NET MVC
(0)
Life
(0)
Book Reviews
(0)
WPF
(0)
Query XML using XPathDocument and XPathNodeIterator
by vipraIT on 7/22/2008 10:49:45 AM
I try to query XML to retreive a particular element value but it gives complete XML document instead of particular element or node. XML document is like-
Autobiography of Bebo
Dev
Robin
999.99
private void QueryXml()
{
XPathDocument document = new XPathDocument("\\books.xml");
XPathNavigator navigator = document.CreateNavigator();
// Select all books authored by Robin
XPathNodeIterator nodes = navigator.Select("descendant::book [author/last-name='Robin']");
while (nodes.MoveNext())
{
Clone the navigator returned by the Current property.
// Use the cloned navigator to get the title element.
XPathNavigator clone = nodes.Current.Clone();
clone.MoveToFirstChild();
lblXml.Text = clone.Value;
}
}
}
Refactor it!
Please log in to refactor the code!
Login