<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>eXclusiveMinds &#187; XML</title>
	<atom:link href="http://eXclusiveMinds.com/tag/xml/feed/" rel="self" type="application/rss+xml" />
	<link>http://eXclusiveMinds.com</link>
	<description>eXclusive resource for programmers, developers and designers</description>
	<lastBuildDate>Sat, 13 Mar 2010 23:28:44 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Select Top XML Nodes using XPath in C#</title>
		<link>http://eXclusiveMinds.com/2009/12/02/select-top-xml-nodes-using-xpath-in-c/</link>
		<comments>http://eXclusiveMinds.com/2009/12/02/select-top-xml-nodes-using-xpath-in-c/#comments</comments>
		<pubDate>Tue, 01 Dec 2009 23:54:04 +0000</pubDate>
		<dc:creator>eXclusiveMinds</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[.NET]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[XML]]></category>
		<category><![CDATA[XPath]]></category>

		<guid isPermaLink="false">http://eXclusiveMinds.com/?p=168</guid>
		<description><![CDATA[Following exampel demonstrates how can we select Top N nodes from an XML document.
We can use method XmlNode.Selec­tNodes and Pass XPath expression as a parameter to select Xml Node.

Sample XML file

&#60;Names&#62;
    &#60;Name&#62;James&#60;/Name&#62;
    &#60;Name&#62;Wyane&#60;/Name&#62;
    &#60;Name&#62;Green&#60;/Name&#62;
    &#60;Name&#62;Ballack&#60;/Name&#62;
    &#60;Name&#62;Gallass&#60;/Name&#62;
    &#60;Name&#62;Rahul&#60;/Name&#62;
 [...]]]></description>
			<content:encoded><![CDATA[<p>Following exampel demonstrates how can we select <strong>Top N</strong> nodes from an XML document.<br />
We can use method <a rel="nofollow" href="http://msdn2.microsoft.com/en-us/library/system.xml.xmlnode.selectnodes.aspx">XmlNode.Selec­tNodes</a> and Pass <strong>XPath</strong> expression as a parameter to select Xml Node.<br />
<span id="more-168"></span><br />
<strong>Sample XML file</strong></p>

<div class="wp_syntax"><table><tr><td><div class="code"><pre class="xml" style="font-family:Consolas; monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;Names<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;Name<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>James<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/Name<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;Name<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>Wyane<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/Name<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;Name<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>Green<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/Name<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;Name<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>Ballack<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/Name<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;Name<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>Gallass<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/Name<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;Name<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>Rahul<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/Name<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;Name<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>Cashmen<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/Name<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/Names<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></td></tr></table></div>

<p>We can get all nodes by using this XPath expression:</p>

<div class="wp_syntax"><table><tr><td><div class="code"><pre class="csharp" style="font-family:Consolas; monospace;"> <span style="color: #008000;">/</span>Names<span style="color: #008000;">/</span>Name.</pre></div></td></tr></table></div>

<p>We can get only top 5 nodes by using XPath expression:</p>

<div class="wp_syntax"><table><tr><td><div class="code"><pre class="csharp" style="font-family:Consolas; monospace;"> <span style="color: #008000;">/</span>Names<span style="color: #008000;">/</span>Name<span style="color: #000000;">&#91;</span>position<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span> <span style="color: #008000;">&lt;=</span> <span style="color: #FF0000;">5</span><span style="color: #000000;">&#93;</span></pre></div></td></tr></table></div>

<p><strong>Sample Code</strong></p>

<div class="wp_syntax"><table><tr><td><div class="code"><pre class="csharp" style="font-family:Consolas; monospace;">XmlDocument doc <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> XmlDocument<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
doc.<span style="color: #0000FF;">LoadXml</span><span style="color: #000000;">&#40;</span>str<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
XmlNodeList nodes <span style="color: #008000;">=</span> doc.<span style="color: #0000FF;">SelectNodes</span><span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;/Names/Name[position() &lt;= 5]&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
<span style="color: #0600FF;">foreach</span> <span style="color: #000000;">&#40;</span>XmlNode node <span style="color: #0600FF;">in</span> nodes<span style="color: #000000;">&#41;</span>
<span style="color: #000000;">&#123;</span>
  Console.<span style="color: #0000FF;">WriteLine</span><span style="color: #000000;">&#40;</span>node.<span style="color: #0000FF;">InnerText</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
<span style="color: #000000;">&#125;</span></pre></div></td></tr></table></div>

<p><strong>OUTPUT:</strong></p>

<div class="wp_syntax"><table><tr><td><div class="code"><pre class="csharp" style="font-family:Consolas; monospace;">Frank
Wyane
Green
Ballack
Gallass</pre></div></td></tr></table></div>

<img src="http://eXclusiveMinds.Com/?ak_action=api_record_view&id=168&type=feed" alt="" />]]></content:encoded>
			<wfw:commentRss>http://eXclusiveMinds.com/2009/12/02/select-top-xml-nodes-using-xpath-in-c/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Select XML Nodes by Name in C#</title>
		<link>http://eXclusiveMinds.com/2009/02/02/select-xml-nodes-by-name-in-c/</link>
		<comments>http://eXclusiveMinds.com/2009/02/02/select-xml-nodes-by-name-in-c/#comments</comments>
		<pubDate>Mon, 02 Feb 2009 00:03:33 +0000</pubDate>
		<dc:creator>eXclusiveMinds</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[.NET]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[XML]]></category>

		<guid isPermaLink="false">http://eXclusiveMinds.com/?p=175</guid>
		<description><![CDATA[We can use XPath expression for finding nodes in a XML file.
For this we can use following method:
i. XmlNode.SelectNodes.
ii.XmlNode.SelectSingleNode.


Sample XML file

&#60;Names&#62;
    &#60;Name&#62;
        &#60;FirstName&#62;Steven&#60;/FirstName&#62;
        &#60;LastName&#62;Danilo&#60;/LastName&#62;
    &#60;/Name&#62;
    &#60;Name&#62;
       [...]]]></description>
			<content:encoded><![CDATA[<p>We can use XPath expression for finding nodes in a XML file.<br />
For this we can use following method:<br />
i. <a rel="nofollow" href="http://msdn2.microsoft.com/en-us/library/system.xml.xmlnode.selectnodes.aspx">XmlNode.SelectNodes</a>.<br />
ii.<a rel="nofollow" href="http://msdn2.microsoft.com/en-us/library/system.xml.xmlnode.selectsinglenode.aspx">XmlNode.SelectSingleNode</a>.<br />
<span id="more-175"></span><br />
<!--more--></p>
<p><strong>Sample XML file</strong></p>

<div class="wp_syntax"><table><tr><td><div class="code"><pre class="xml" style="font-family:Consolas; monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;Names<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;Name<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;FirstName<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>Steven<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/FirstName<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;LastName<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>Danilo<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/LastName<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/Name<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;Name<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;FirstName<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>Milner<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/FirstName<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;LastName<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>Perez<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/LastName<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/Name<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/Names<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></td></tr></table></div>

<p><strong>Example Code: </strong></p>

<div class="wp_syntax"><table><tr><td><div class="code"><pre class="csharp" style="font-family:Consolas; monospace;">XmlDocument doc <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> XmlDocument<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
doc.<span style="color: #0000FF;">LoadXml</span><span style="color: #000000;">&#40;</span>xmlString<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span> 
XmlNodeList nodes <span style="color: #008000;">=</span> doc.<span style="color: #0000FF;">SelectNodes</span><span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;/Names/Name&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
<span style="color: #008080; font-style: italic;">//Iterate through node list</span>
<span style="color: #0600FF;">foreach</span> <span style="color: #000000;">&#40;</span>XmlNode node <span style="color: #0600FF;">in</span> nodes<span style="color: #000000;">&#41;</span>
<span style="color: #000000;">&#123;</span>
	<span style="color: #008080; font-style: italic;">//Get first name</span>
	<span style="color: #FF0000;">string</span> firstName <span style="color: #008000;">=</span> node<span style="color: #000000;">&#91;</span><span style="color: #666666;">&quot;FirstName&quot;</span><span style="color: #000000;">&#93;</span>.<span style="color: #0000FF;">InnerText</span><span style="color: #008000;">;</span>
	<span style="color: #008080; font-style: italic;">//Get last name  </span>
	<span style="color: #FF0000;">string</span> lastName <span style="color: #008000;">=</span> node<span style="color: #000000;">&#91;</span><span style="color: #666666;">&quot;LastName&quot;</span><span style="color: #000000;">&#93;</span>.<span style="color: #0000FF;">InnerText</span><span style="color: #008000;">;</span>
	<span style="color: #008080; font-style: italic;">//Pring Name  </span>
	Console.<span style="color: #0000FF;">Write</span><span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;Name: {0} {1}&quot;</span>, firstName, lastName<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
<span style="color: #000000;">&#125;</span></pre></div></td></tr></table></div>

<p><strong>OUTPUT:</strong></p>

<div class="wp_syntax"><table><tr><td><div class="code"><pre class="csharp" style="font-family:Consolas; monospace;">Name<span style="color: #008000;">:</span> Steven Danilo
Name<span style="color: #008000;">:</span> Milner Perez</pre></div></td></tr></table></div>

<img src="http://eXclusiveMinds.Com/?ak_action=api_record_view&id=175&type=feed" alt="" />]]></content:encoded>
			<wfw:commentRss>http://eXclusiveMinds.com/2009/02/02/select-xml-nodes-by-name-in-c/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Select XML Nodes by Attribute Value in C#</title>
		<link>http://eXclusiveMinds.com/2009/01/02/select-xml-nodes-by-attribute-value-in-c/</link>
		<comments>http://eXclusiveMinds.com/2009/01/02/select-xml-nodes-by-attribute-value-in-c/#comments</comments>
		<pubDate>Thu, 01 Jan 2009 23:59:29 +0000</pubDate>
		<dc:creator>eXclusiveMinds</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[.NET]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[XML]]></category>

		<guid isPermaLink="false">http://eXclusiveMinds.com/?p=173</guid>
		<description><![CDATA[Following example demonstrates about selecting nodes from XML file by attribute value.
To retrieve list of xml nodes which are selected by XPath expression use method XmlNode.Selec­tNodes.

Sample XML File

&#60;Names&#62;
    &#60;Name type=&#34;M&#34;&#62;Rahul&#60;/Name&#62;
    &#60;Name type=&#34;F&#34;&#62;William&#60;/Name&#62;
    &#60;Name type=&#34;M&#34;&#62;Zhang&#60;/Name&#62;
&#60;/Names&#62;

Following  XPath expression gives all nodes:

/Names/Name

Following XPath expression gives only name of [...]]]></description>
			<content:encoded><![CDATA[<p>Following example demonstrates about selecting nodes from XML file by attribute value.<br />
To retrieve list of xml nodes which are selected by XPath expression use method <strong><a rel="nofollow" href="http://msdn2.microsoft.com/en-us/library/system.xml.xmlnode.selectnodes.aspx">XmlNode.Selec­tNodes</a></strong>.<br />
<span id="more-173"></span><br />
<strong>Sample XML File</strong></p>

<div class="wp_syntax"><table><tr><td><div class="code"><pre class="xml" style="font-family:Consolas; monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;Names<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;Name</span> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">&quot;M&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>Rahul<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/Name<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;Name</span> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">&quot;F&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>William<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/Name<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;Name</span> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">&quot;M&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>Zhang<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/Name<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/Names<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></td></tr></table></div>

<p>Following  XPath expression gives all nodes:</p>

<div class="wp_syntax"><table><tr><td><div class="code"><pre class="csharp" style="font-family:Consolas; monospace;"><span style="color: #008000;">/</span>Names<span style="color: #008000;">/</span>Name</pre></div></td></tr></table></div>

<p>Following XPath expression gives only name of males:</p>

<div class="wp_syntax"><table><tr><td><div class="code"><pre class="csharp" style="font-family:Consolas; monospace;"><span style="color: #008000;">/</span>Names<span style="color: #008000;">/</span>Name<span style="color: #000000;">&#91;</span>@type<span style="color: #008000;">=</span><span style="color: #666666;">'M'</span><span style="color: #000000;">&#93;</span></pre></div></td></tr></table></div>

<p>.</p>

<div class="wp_syntax"><table><tr><td><div class="code"><pre class="csharp" style="font-family:Consolas; monospace;">XmlDocument doc <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> XmlDocument<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
<span style="color: #008080; font-style: italic;">//Load xml</span>
xml.<span style="color: #0000FF;">LoadXml</span><span style="color: #000000;">&#40;</span>str<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span> 
&nbsp;
XmlNodeList nodes <span style="color: #008000;">=</span>doc.<span style="color: #0000FF;">SelectNodes</span><span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;/Names/Name[@type='M']&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
<span style="color: #008080; font-style: italic;">//Iterate through list of nodes</span>
<span style="color: #0600FF;">foreach</span> <span style="color: #000000;">&#40;</span>XmlNode node <span style="color: #0600FF;">in</span> nodes<span style="color: #000000;">&#41;</span>
<span style="color: #000000;">&#123;</span>
  Console.<span style="color: #0000FF;">WriteLine</span><span style="color: #000000;">&#40;</span>node.<span style="color: #0000FF;">InnerText</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
<span style="color: #000000;">&#125;</span></pre></div></td></tr></table></div>

<p><strong>The output is:</strong></p>

<div class="wp_syntax"><table><tr><td><div class="code"><pre class="csharp" style="font-family:Consolas; monospace;">Rahul
Zhang</pre></div></td></tr></table></div>

<img src="http://eXclusiveMinds.Com/?ak_action=api_record_view&id=173&type=feed" alt="" />]]></content:encoded>
			<wfw:commentRss>http://eXclusiveMinds.com/2009/01/02/select-xml-nodes-by-attribute-value-in-c/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
