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,
161 this.namespaceManager = nsMgr;
163 this.DocTypeName = dtd.Name;
164 this.PublicId = dtd.PublicId;
165 this.SystemId = dtd.SystemId;
166 this.InternalSubset = dtd.InternalSubset;
171 this.BaseURI = baseURI;
172 this.XmlLang = xmlLang;
173 this.xmlSpace = xmlSpace;
175 contextItems = new ArrayList ();
181 private string baseURI = String.Empty;
182 private string docTypeName = String.Empty;
183 private Encoding encoding;
184 private string internalSubset = String.Empty;
185 private XmlNamespaceManager namespaceManager;
186 private XmlNameTable nameTable;
187 private string publicID = String.Empty;
188 private string systemID = String.Empty;
189 private string xmlLang = String.Empty;
190 private XmlSpace xmlSpace;
191 private ArrayList contextItems;
192 private int contextItemCount;
193 private DTDObjectModel dtd;
199 public string BaseURI {
200 get { return baseURI; }
201 set { baseURI = value != null ? value : String.Empty; }
204 public string DocTypeName {
205 get { return docTypeName != null ? docTypeName : dtd != null ? dtd.Name : null; }
206 set { docTypeName = value != null ? value : String.Empty; }
209 internal DTDObjectModel Dtd {
214 public Encoding Encoding {
215 get { return encoding; }
216 set { encoding = value; }
219 public string InternalSubset {
220 get { return internalSubset != null ? internalSubset : dtd != null ? dtd.InternalSubset : null; }
221 set { internalSubset = value != null ? value : String.Empty; }
224 public XmlNamespaceManager NamespaceManager {
225 get { return namespaceManager; }
226 set { namespaceManager = value; }
229 public XmlNameTable NameTable {
230 get { return nameTable; }
231 set { nameTable = value; }
234 public string PublicId {
235 get { return publicID != null ? publicID : dtd != null ? dtd.PublicId : null; }
236 set { publicID = value != null ? value : String.Empty; }
239 public string SystemId {
240 get { return systemID != null ? systemID : dtd != null ? dtd.SystemId : null; }
241 set { systemID = value != null ? value : String.Empty; }
244 public string XmlLang {
245 get { return xmlLang; }
246 set { xmlLang = value != null ? value : String.Empty; }
249 public XmlSpace XmlSpace {
250 get { return xmlSpace; }
251 set { xmlSpace = value; }
257 internal void PushScope ()
259 ContextItem item = null;
260 if (contextItems.Count == contextItemCount) {
261 item = new ContextItem ();
262 contextItems.Add (item);
265 item = (ContextItem) contextItems [contextItemCount];
266 item.BaseURI = BaseURI;
267 item.XmlLang = XmlLang;
268 item.XmlSpace = XmlSpace;
272 internal void PopScope ()
274 if (contextItemCount == 0)
275 throw new XmlException ("Unexpected end of element scope.");
277 ContextItem prev = (ContextItem) contextItems [contextItemCount];
278 baseURI = prev.BaseURI;
279 xmlLang = prev.XmlLang;
280 xmlSpace = prev.XmlSpace;