The Labs \ Source Viewer \ SSCLI \ System.Xml \ XmlChildNodes

  1. //------------------------------------------------------------------------------
  2. // <copyright file="XmlChildNodes.cs" company="Microsoft">
  3. //
  4. // Copyright (c) 2006 Microsoft Corporation. All rights reserved.
  5. //
  6. // The use and distribution terms for this software are contained in the file
  7. // named license.txt, which can be found in the root of this distribution.
  8. // By using this software in any fashion, you are agreeing to be bound by the
  9. // terms of this license.
  10. //
  11. // You must not remove this notice, or any other, from this software.
  12. //
  13. // </copyright>
  14. //------------------------------------------------------------------------------
  15. namespace System.Xml
  16. {
  17.     using System.Collections;
  18.    
  19.     internal class XmlChildNodes : XmlNodeList
  20.     {
  21.         private XmlNode container;
  22.        
  23.         public XmlChildNodes(XmlNode container)
  24.         {
  25.             this.container = container;
  26.         }
  27.        
  28.         public override XmlNode Item(int i)
  29.         {
  30.             // Out of range indexes return a null XmlNode
  31.             if (i < 0)
  32.                 return null;
  33.             for (XmlNode n = container.FirstChild; n != null; n = n.NextSibling,i--) {
  34.                 if (i == 0)
  35.                     return n;
  36.             }
  37.             return null;
  38.         }
  39.        
  40.         public override int Count {
  41.             get {
  42.                 int c = 0;
  43.                 for (XmlNode n = container.FirstChild; n != null; n = n.NextSibling) {
  44.                     c++;
  45.                 }
  46.                 return c;
  47.             }
  48.         }
  49.        
  50.         public override IEnumerator GetEnumerator()
  51.         {
  52.             if (container.FirstChild == null) {
  53.                 return XmlDocument.EmptyEnumerator;
  54.             }
  55.             else {
  56.                 return new XmlChildEnumerator(container);
  57.             }
  58.         }
  59.     }
  60. }

Developer Fusion