The Labs \ Source Viewer \ SSCLI \ System.Xml.Schema \ SchemaNamespaceManager

  1. //------------------------------------------------------------------------------
  2. // <copyright file="SchemaNamespaceManager.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. // <owner current="true" primary="true">priyal</owner>
  15. //------------------------------------------------------------------------------
  16. namespace System.Xml.Schema
  17. {
  18.     using System;
  19.     using System.Diagnostics;
  20.     using System.Collections;
  21.    
  22.     internal class SchemaNamespaceManager : XmlNamespaceManager
  23.     {
  24.         XmlSchemaObject node;
  25.        
  26.         public SchemaNamespaceManager(XmlSchemaObject node)
  27.         {
  28.             this.node = node;
  29.         }
  30.        
  31.         public override string LookupNamespace(string prefix)
  32.         {
  33.             if (prefix == "xml") {
  34.                 //Special case for the XML namespace
  35.                 return XmlReservedNs.NsXml;
  36.             }
  37.             Hashtable namespaces;
  38.             for (XmlSchemaObject current = node; current != null; current = current.Parent) {
  39.                 namespaces = current.Namespaces.Namespaces;
  40.                 if (namespaces != null && namespaces.Count > 0) {
  41.                     object uri = namespaces[prefix];
  42.                     if (uri != null)
  43.                         return (string)uri;
  44.                 }
  45.             }
  46.             return prefix.Length == 0 ? string.Empty : null;
  47.         }
  48.        
  49.         public override string LookupPrefix(string ns)
  50.         {
  51.             if (ns == XmlReservedNs.NsXml) {
  52.                 //Special case for the XML namespace
  53.                 return "xml";
  54.             }
  55.             Hashtable namespaces;
  56.             for (XmlSchemaObject current = node; current != null; current = current.Parent) {
  57.                 namespaces = current.Namespaces.Namespaces;
  58.                 if (namespaces != null && namespaces.Count > 0) {
  59.                     foreach (DictionaryEntry entry in namespaces) {
  60.                         if (entry.Value.Equals(ns)) {
  61.                             return (string)entry.Key;
  62.                         }
  63.                     }
  64.                 }
  65.             }
  66.             return null;
  67.         }
  68.        
  69.     }
  70.     //SchemaNamespaceManager
  71. }

Developer Fusion