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;
37 using XmlTextReaderImpl = Mono.Xml2.XmlTextReader;
39 using XmlTextReaderImpl = System.Xml.XmlTextReader;
44 public class XmlParserContext
49 public string BaseURI;
50 public string XmlLang;
51 public XmlSpace XmlSpace;
57 public XmlParserContext (
59 XmlNamespaceManager nsMgr,
78 public XmlParserContext (
80 XmlNamespaceManager nsMgr,
100 public XmlParserContext (
102 XmlNamespaceManager nsMgr,
106 string internalSubset,
126 public XmlParserContext (
128 XmlNamespaceManager nsMgr,
132 string internalSubset,
140 (docTypeName != null && docTypeName != String.Empty) ?
141 new XmlTextReaderImpl ("", nt).GenerateDTDObjectModel (
142 docTypeName, pubId, sysId, internalSubset) : null,
150 internal XmlParserContext (XmlNameTable nt,
151 XmlNamespaceManager nsMgr,
159 this.nameTable = nsMgr == null ? new NameTable () : nsMgr.NameTable;
163 this.namespaceManager = nsMgr != null ? nsMgr : new XmlNamespaceManager (nameTable);
165 this.DocTypeName = dtd.Name;
166 this.PublicId = dtd.PublicId;
167 this.SystemId = dtd.SystemId;
168 this.InternalSubset = dtd.InternalSubset;
173 this.BaseURI = baseURI;
174 this.XmlLang = xmlLang;
175 this.xmlSpace = xmlSpace;
177 contextItems = new ArrayList ();
183 private string baseURI = String.Empty;
184 private string docTypeName = String.Empty;
185 private Encoding encoding;
186 private string internalSubset = String.Empty;
187 private XmlNamespaceManager namespaceManager;
188 private XmlNameTable nameTable;
189 private string publicID = String.Empty;
190 private string systemID = String.Empty;
191 private string xmlLang = String.Empty;
192 private XmlSpace xmlSpace;
193 private ArrayList contextItems;
194 private int contextItemCount;
195 private DTDObjectModel dtd;
201 public string BaseURI {
202 get { return baseURI; }
203 set { baseURI = value != null ? value : String.Empty; }
206 public string DocTypeName {
207 get { return docTypeName != null ? docTypeName : dtd != null ? dtd.Name : null; }
208 set { docTypeName = value != null ? value : String.Empty; }
211 internal DTDObjectModel Dtd {
216 public Encoding Encoding {
217 get { return encoding; }
218 set { encoding = value; }
221 public string InternalSubset {
222 get { return internalSubset != null ? internalSubset : dtd != null ? dtd.InternalSubset : null; }
223 set { internalSubset = value != null ? value : String.Empty; }
226 public XmlNamespaceManager NamespaceManager {
227 get { return namespaceManager; }
228 set { namespaceManager = value; }
231 public XmlNameTable NameTable {
232 get { return nameTable; }
233 set { nameTable = value; }
236 public string PublicId {
237 get { return publicID != null ? publicID : dtd != null ? dtd.PublicId : null; }
238 set { publicID = value != null ? value : String.Empty; }
241 public string SystemId {
242 get { return systemID != null ? systemID : dtd != null ? dtd.SystemId : null; }
243 set { systemID = value != null ? value : String.Empty; }
246 public string XmlLang {
247 get { return xmlLang; }
248 set { xmlLang = value != null ? value : String.Empty; }
251 public XmlSpace XmlSpace {
252 get { return xmlSpace; }
253 set { xmlSpace = value; }
259 internal void PushScope ()
261 ContextItem item = null;
262 if (contextItems.Count == contextItemCount) {
263 item = new ContextItem ();
264 contextItems.Add (item);
267 item = (ContextItem) contextItems [contextItemCount];
268 item.BaseURI = BaseURI;
269 item.XmlLang = XmlLang;
270 item.XmlSpace = XmlSpace;
274 internal void PopScope ()
276 if (contextItemCount == 0)
277 throw new XmlException ("Unexpected end of element scope.");
279 ContextItem prev = (ContextItem) contextItems [contextItemCount];
280 baseURI = prev.BaseURI;
281 xmlLang = prev.XmlLang;
282 xmlSpace = prev.XmlSpace;