2 // System.Xml.XmlParserContext
5 // Jason Diamond (jason@injektilo.org)
6 // Atsushi Enomoto (ginga@kit.hi-ho.ne.jp)
8 // (C) 2001, 2002 Jason Diamond http://injektilo.org/
9 // (C) 2003 Atsushi Enomoto
13 // Permission is hereby granted, free of charge, to any person obtaining
14 // a copy of this software and associated documentation files (the
15 // "Software"), to deal in the Software without restriction, including
16 // without limitation the rights to use, copy, modify, merge, publish,
17 // distribute, sublicense, and/or sell copies of the Software, and to
18 // permit persons to whom the Software is furnished to do so, subject to
19 // the following conditions:
21 // The above copyright notice and this permission notice shall be
22 // included in all copies or substantial portions of the Software.
24 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
25 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
26 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
27 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
28 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
29 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
30 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
32 using System.Collections;
38 using XmlTextReaderImpl = Mono.Xml2.XmlTextReader;
40 using XmlTextReaderImpl = System.Xml.XmlTextReader;
45 public class XmlParserContext
50 public string BaseURI;
51 public string XmlLang;
52 public XmlSpace XmlSpace;
58 public XmlParserContext (
60 XmlNamespaceManager nsMgr,
79 public XmlParserContext (
81 XmlNamespaceManager nsMgr,
101 public XmlParserContext (
103 XmlNamespaceManager nsMgr,
107 string internalSubset,
127 public XmlParserContext (
129 XmlNamespaceManager nsMgr,
133 string internalSubset,
141 (docTypeName != null && docTypeName != String.Empty) ?
142 new XmlTextReaderImpl (TextReader.Null, nt).GenerateDTDObjectModel (
143 docTypeName, pubId, sysId, internalSubset) : null,
151 internal XmlParserContext (XmlNameTable nt,
152 XmlNamespaceManager nsMgr,
159 this.namespaceManager = nsMgr;
160 this.nameTable = nt != null ? nt : nsMgr != null ? nsMgr.NameTable : null;
162 this.DocTypeName = dtd.Name;
163 this.PublicId = dtd.PublicId;
164 this.SystemId = dtd.SystemId;
165 this.InternalSubset = dtd.InternalSubset;
170 this.BaseURI = baseURI;
171 this.XmlLang = xmlLang;
172 this.xmlSpace = xmlSpace;
174 contextItems = new ArrayList ();
180 private string baseURI = String.Empty;
181 private string docTypeName = String.Empty;
182 private Encoding encoding;
183 private string internalSubset = String.Empty;
184 private XmlNamespaceManager namespaceManager;
185 private XmlNameTable nameTable;
186 private string publicID = String.Empty;
187 private string systemID = String.Empty;
188 private string xmlLang = String.Empty;
189 private XmlSpace xmlSpace;
190 private ArrayList contextItems;
191 private int contextItemCount;
192 private DTDObjectModel dtd;
198 public string BaseURI {
199 get { return baseURI; }
200 set { baseURI = value != null ? value : String.Empty; }
203 public string DocTypeName {
204 get { return docTypeName != null ? docTypeName : dtd != null ? dtd.Name : null; }
205 set { docTypeName = value != null ? value : String.Empty; }
208 internal DTDObjectModel Dtd {
213 public Encoding Encoding {
214 get { return encoding; }
215 set { encoding = value; }
218 public string InternalSubset {
219 get { return internalSubset != null ? internalSubset : dtd != null ? dtd.InternalSubset : null; }
220 set { internalSubset = value != null ? value : String.Empty; }
223 public XmlNamespaceManager NamespaceManager {
224 get { return namespaceManager; }
225 set { namespaceManager = value; }
228 public XmlNameTable NameTable {
229 get { return nameTable; }
230 set { nameTable = value; }
233 public string PublicId {
234 get { return publicID != null ? publicID : dtd != null ? dtd.PublicId : null; }
235 set { publicID = value != null ? value : String.Empty; }
238 public string SystemId {
239 get { return systemID != null ? systemID : dtd != null ? dtd.SystemId : null; }
240 set { systemID = value != null ? value : String.Empty; }
243 public string XmlLang {
244 get { return xmlLang; }
245 set { xmlLang = value != null ? value : String.Empty; }
248 public XmlSpace XmlSpace {
249 get { return xmlSpace; }
250 set { xmlSpace = value; }
256 internal void PushScope ()
258 ContextItem item = null;
259 if (contextItems.Count == contextItemCount) {
260 item = new ContextItem ();
261 contextItems.Add (item);
264 item = (ContextItem) contextItems [contextItemCount];
265 item.BaseURI = BaseURI;
266 item.XmlLang = XmlLang;
267 item.XmlSpace = XmlSpace;
271 internal void PopScope ()
273 if (contextItemCount == 0)
274 throw new XmlException ("Unexpected end of element scope.");
276 ContextItem prev = (ContextItem) contextItems [contextItemCount];
277 baseURI = prev.BaseURI;
278 xmlLang = prev.XmlLang;
279 xmlSpace = prev.XmlSpace;