fork(1) download
  1. using System;
  2. using System.IO;
  3. using System.Xml;
  4.  
  5. public class MyClass
  6. {
  7.  
  8. public static void Main(string[] args)
  9. {
  10. string xmlStr = @"<?xml version='1.0' encoding='UTF-8' standalone='yes'?>
  11. <Images xmlns='http://o...content-available-to-author-only...e.net/schemas/server'
  12. xmlns:ns9='http://o...content-available-to-author-only...e.net/schemas/multigeo'
  13. xmlns:ns5='http://o...content-available-to-author-only...e.net/schemas/vip'
  14. xmlns:ns12='http://o...content-available-to-author-only...e.net/schemas/storage'
  15. xmlns:ns6='http://o...content-available-to-author-only...e.net/schemas/whitelabel'
  16. xmlns:ns13='http://o...content-available-to-author-only...e.net/schemas/manualimport'
  17. xmlns:ns7='http://o...content-available-to-author-only...e.net/schemas/datacenter'
  18. xmlns:ns10='http://o...content-available-to-author-only...e.net/schemas/reset'
  19. xmlns:ns8='http://o...content-available-to-author-only...e.net/schemas/general'
  20. xmlns:ns11='http://o...content-available-to-author-only...e.net/schemas/support'
  21. xmlns:ns2='http://o...content-available-to-author-only...e.net/schemas/directory'
  22. xmlns:ns4='http://o...content-available-to-author-only...e.net/schemas/network'
  23. xmlns:ns3='http://o...content-available-to-author-only...e.net/schemas/organization'>
  24. <Image>
  25. <id>mcd93jf8dd</id>
  26. <name>cat</name>
  27. <color>yellow</color>
  28. </Image>
  29. <Image>
  30. <id>d4b8l23sas</id>
  31. <name>dog</name>
  32. <color>yellow</color>
  33. </Image>
  34. </Images>";
  35. XmlDocument xml = new XmlDocument();
  36. // put the string into a stream
  37. using (Stream stream = new MemoryStream())
  38. {
  39. StreamWriter writer = new StreamWriter(stream);
  40. writer.Write(xmlStr);
  41. writer.Flush();
  42. stream.Position = 0;
  43.  
  44. xml.Load(stream);
  45. }
  46.  
  47. XmlNamespaceManager nsm = new XmlNamespaceManager(xml.NameTable);
  48. // The prefix can be anything as long as you use it consistently
  49. nsm.AddNamespace("i", "http://o...content-available-to-author-only...e.net/schemas/server");
  50.  
  51. XmlNodeList ids = xml.SelectNodes("/i:Images/i:Image[i:color = 'yellow']/i:id", nsm);
  52. Console.WriteLine("ids.Count = {0}", ids.Count);
  53. XmlNodeList names = xml.SelectNodes("/i:Images/i:Image[i:color = 'yellow']/i:name", nsm);
  54. Console.WriteLine("names.Count = {0}", names.Count);
  55. foreach (XmlNode yellowImage in xml.SelectNodes("/i:Images/i:Image[i:color = 'yellow']", nsm))
  56. {
  57. string id = yellowImage.SelectSingleNode("i:id", nsm).InnerText;
  58. string name = yellowImage.SelectSingleNode("i:name", nsm).InnerText;
  59.  
  60. Console.WriteLine("id = {0}, name = {1}", id, name);
  61. }
  62. }
  63. }
Success #stdin #stdout 0.17s 34888KB
stdin
Standard input is empty
stdout
ids.Count = 2
names.Count = 2
id = mcd93jf8dd, name = cat
id = d4b8l23sas, name = dog