XmlParserContext.cs 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244
  1. //
  2. // System.Xml.XmlParserContext
  3. //
  4. // Author:
  5. // Jason Diamond ([email protected])
  6. // Atsushi Enomoto ([email protected])
  7. //
  8. // (C) 2001, 2002 Jason Diamond http://injektilo.org/
  9. // (C) 2003 Atsushi Enomoto
  10. //
  11. using System.Collections;
  12. using System.Text;
  13. using Mono.Xml;
  14. namespace System.Xml
  15. {
  16. public class XmlParserContext
  17. {
  18. #region Constructors
  19. public XmlParserContext (
  20. XmlNameTable nt,
  21. XmlNamespaceManager nsMgr,
  22. string xmlLang,
  23. XmlSpace xmlSpace) :
  24. this (
  25. nt,
  26. nsMgr,
  27. null,
  28. null,
  29. null,
  30. null,
  31. null,
  32. xmlLang,
  33. xmlSpace,
  34. null
  35. )
  36. {
  37. }
  38. public XmlParserContext (
  39. XmlNameTable nt,
  40. XmlNamespaceManager nsMgr,
  41. string xmlLang,
  42. XmlSpace xmlSpace,
  43. Encoding enc) :
  44. this (
  45. nt,
  46. nsMgr,
  47. null,
  48. null,
  49. null,
  50. null,
  51. null,
  52. xmlLang,
  53. xmlSpace,
  54. enc
  55. )
  56. {
  57. }
  58. public XmlParserContext (
  59. XmlNameTable nt,
  60. XmlNamespaceManager nsMgr,
  61. string docTypeName,
  62. string pubId,
  63. string sysId,
  64. string internalSubset,
  65. string baseURI,
  66. string xmlLang,
  67. XmlSpace xmlSpace) :
  68. this (
  69. nt,
  70. nsMgr,
  71. docTypeName,
  72. pubId,
  73. sysId,
  74. internalSubset,
  75. baseURI,
  76. xmlLang,
  77. xmlSpace,
  78. null
  79. )
  80. {
  81. }
  82. public XmlParserContext (
  83. XmlNameTable nt,
  84. XmlNamespaceManager nsMgr,
  85. string docTypeName,
  86. string pubId,
  87. string sysId,
  88. string internalSubset,
  89. string baseURI,
  90. string xmlLang,
  91. XmlSpace xmlSpace,
  92. Encoding enc)
  93. : this (
  94. nt,
  95. nsMgr,
  96. (docTypeName != null && docTypeName != String.Empty) ?
  97. new XmlTextReader ("", nt).GenerateDTDObjectModel (
  98. docTypeName, pubId, sysId, internalSubset) : null,
  99. baseURI,
  100. xmlLang,
  101. xmlSpace,
  102. enc)
  103. {
  104. }
  105. internal XmlParserContext (XmlNameTable nt,
  106. XmlNamespaceManager nsMgr,
  107. DTDObjectModel dtd,
  108. string baseURI,
  109. string xmlLang,
  110. XmlSpace xmlSpace,
  111. Encoding enc)
  112. {
  113. if (nt == null)
  114. this.nameTable = nsMgr.NameTable;
  115. else
  116. this.NameTable = nt;
  117. this.namespaceManager = nsMgr;
  118. if (dtd != null) {
  119. this.docTypeName = dtd.Name;
  120. this.publicID = dtd.PublicId;
  121. this.systemID = dtd.SystemId;
  122. this.internalSubset = dtd.InternalSubset;
  123. this.dtd = dtd;
  124. }
  125. this.encoding = enc;
  126. PushScope ();
  127. this.BaseURI = baseURI != null ? baseURI : String.Empty;
  128. this.XmlLang = xmlLang;
  129. this.XmlSpace = xmlSpace;
  130. }
  131. #endregion
  132. #region Fields
  133. private string docTypeName;
  134. private Encoding encoding;
  135. private string internalSubset;
  136. private XmlNamespaceManager namespaceManager;
  137. private XmlNameTable nameTable;
  138. private string publicID;
  139. private string systemID;
  140. private HighWaterStack scopeStack = new HighWaterStack (50);
  141. Scope current;
  142. private DTDObjectModel dtd;
  143. #endregion
  144. #region Properties
  145. public string BaseURI {
  146. get { return current.baseUri; }
  147. set { current.baseUri = value; }
  148. }
  149. public string DocTypeName {
  150. get { return docTypeName != null ? docTypeName : dtd != null ? dtd.Name : null; }
  151. set { docTypeName = value; }
  152. }
  153. internal DTDObjectModel Dtd {
  154. get { return dtd; }
  155. set { dtd = value; }
  156. }
  157. public Encoding Encoding {
  158. get { return encoding; }
  159. set { encoding = value; }
  160. }
  161. public string InternalSubset {
  162. get { return internalSubset != null ? internalSubset : dtd != null ? dtd.InternalSubset : null; }
  163. set { internalSubset = value; }
  164. }
  165. public XmlNamespaceManager NamespaceManager {
  166. get { return namespaceManager; }
  167. set { namespaceManager = value; }
  168. }
  169. public XmlNameTable NameTable {
  170. get { return nameTable; }
  171. set { nameTable = value; }
  172. }
  173. public string PublicId {
  174. get { return publicID != null ? publicID : dtd != null ? dtd.PublicId : null; }
  175. set { publicID = value; }
  176. }
  177. public string SystemId {
  178. get { return systemID != null ? systemID : dtd != null ? dtd.SystemId : null; }
  179. set { systemID = value; }
  180. }
  181. public string XmlLang {
  182. get { return current.xmlLang; }
  183. set { current.xmlLang = value; }
  184. }
  185. public XmlSpace XmlSpace {
  186. get { return current.xmlSpace; }
  187. set { current.xmlSpace = value; }
  188. }
  189. #endregion
  190. #region Methods
  191. internal void PushScope ()
  192. {
  193. current = (Scope)scopeStack.Push ();
  194. if (current == null) {
  195. current = new Scope ();
  196. scopeStack.AddToTop (current);
  197. } else {
  198. current.baseUri = String.Empty;
  199. current.xmlLang = String.Empty;
  200. current.xmlSpace = XmlSpace.None;
  201. }
  202. }
  203. internal void PopScope ()
  204. {
  205. current = (Scope)scopeStack.Pop ();
  206. }
  207. class Scope {
  208. public string baseUri, xmlLang;
  209. public XmlSpace xmlSpace;
  210. public Scope () {}
  211. }
  212. #endregion
  213. }
  214. }