using System;
using System.IO;
using System.Xml;
public class MyClass
{
public static void Main(string[] args)
{
string xmlStr = @"<?xml version='1.0' encoding='UTF-8' standalone='yes'?>
<Images xmlns='http://o...content-available-to-author-only...e.net/schemas/server'
xmlns:ns9='http://o...content-available-to-author-only...e.net/schemas/multigeo'
xmlns:ns5='http://o...content-available-to-author-only...e.net/schemas/vip'
xmlns:ns12='http://o...content-available-to-author-only...e.net/schemas/storage'
xmlns:ns6='http://o...content-available-to-author-only...e.net/schemas/whitelabel'
xmlns:ns13='http://o...content-available-to-author-only...e.net/schemas/manualimport'
xmlns:ns7='http://o...content-available-to-author-only...e.net/schemas/datacenter'
xmlns:ns10='http://o...content-available-to-author-only...e.net/schemas/reset'
xmlns:ns8='http://o...content-available-to-author-only...e.net/schemas/general'
xmlns:ns11='http://o...content-available-to-author-only...e.net/schemas/support'
xmlns:ns2='http://o...content-available-to-author-only...e.net/schemas/directory'
xmlns:ns4='http://o...content-available-to-author-only...e.net/schemas/network'
xmlns:ns3='http://o...content-available-to-author-only...e.net/schemas/organization'>
<Image>
<id>mcd93jf8dd</id>
<name>cat</name>
<color>yellow</color>
</Image>
<Image>
<id>d4b8l23sas</id>
<name>dog</name>
<color>yellow</color>
</Image>
</Images>";
XmlDocument xml = new XmlDocument();
// put the string into a stream
using (Stream stream = new MemoryStream())
{
StreamWriter writer = new StreamWriter(stream);
writer.Write(xmlStr);
writer.Flush();
stream.Position = 0;
xml.Load(stream);
}
XmlNamespaceManager nsm = new XmlNamespaceManager(xml.NameTable);
// The prefix can be anything as long as you use it consistently
nsm.AddNamespace("i", "http://o...content-available-to-author-only...e.net/schemas/server");
XmlNodeList ids = xml.SelectNodes("/i:Images/i:Image[i:color = 'yellow']/i:id", nsm);
Console.WriteLine("ids.Count = {0}", ids.Count);
XmlNodeList names = xml.SelectNodes("/i:Images/i:Image[i:color = 'yellow']/i:name", nsm);
Console.WriteLine("names.Count = {0}", names.Count);
foreach (XmlNode yellowImage in xml.SelectNodes("/i:Images/i:Image[i:color = 'yellow']", nsm))
{
string id = yellowImage.SelectSingleNode("i:id", nsm).InnerText;
string name = yellowImage.SelectSingleNode("i:name", nsm).InnerText;
Console.WriteLine("id = {0}, name = {1}", id, name);
}
}
}