XmlSerializerNamespaces.cs 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. //
  2. // XmlSerializerNamespaces.cs:
  3. //
  4. // Author:
  5. // John Donagher ([email protected])
  6. //
  7. // (C) 2002 John Donagher
  8. //
  9. using System;
  10. using System.Xml;
  11. using System.Collections;
  12. namespace System.Xml.Serialization
  13. {
  14. /// <summary>
  15. /// Summary description for XmlSerializerNamespaces.
  16. /// </summary>
  17. public class XmlSerializerNamespaces
  18. {
  19. private Hashtable namespaces;
  20. public XmlSerializerNamespaces ()
  21. {
  22. namespaces = new Hashtable ();
  23. }
  24. public XmlSerializerNamespaces(XmlQualifiedName[] namespaces)
  25. : this()
  26. {
  27. foreach(XmlQualifiedName qname in namespaces)
  28. {
  29. this.namespaces[qname.Name] = qname;
  30. }
  31. }
  32. public XmlSerializerNamespaces(XmlSerializerNamespaces namespaces)
  33. : this(namespaces.ToArray())
  34. {}
  35. public void Add (string prefix, string ns)
  36. {
  37. XmlQualifiedName qname = new XmlQualifiedName(prefix,ns);
  38. namespaces[qname.Name] = qname;
  39. }
  40. public XmlQualifiedName[] ToArray ()
  41. {
  42. XmlQualifiedName[] array = new XmlQualifiedName[namespaces.Count];
  43. namespaces.Values.CopyTo(array,0);
  44. return array;
  45. }
  46. public int Count
  47. {
  48. get{ return namespaces.Count; }
  49. }
  50. internal string GetPrefix(string Ns)
  51. {
  52. foreach(string prefix in namespaces.Keys)
  53. {
  54. if(Ns == ((XmlQualifiedName)namespaces[prefix]).Namespace)
  55. return prefix;
  56. }
  57. return null;
  58. }
  59. internal Hashtable Namespaces
  60. {
  61. get {
  62. return namespaces;
  63. }
  64. }
  65. }
  66. }