Merge pull request #347 from JamesB7/master
[mono.git] / mcs / class / System.XML / System.Xml.XPath / XPathDocument.cs
1 //
2 // System.Xml.XPath.XPathDocument
3 //
4 // Authors:
5 //   Tim Coleman (tim@timcoleman.com)
6 //   Atsushi Enomoto (ginga@kit.hi-ho.ne.jp)
7 //
8 // (C) Copyright 2002 Tim Coleman
9 // (C) 2003 Atsushi Enomoto
10 //
11
12 //
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:
20 // 
21 // The above copyright notice and this permission notice shall be
22 // included in all copies or substantial portions of the Software.
23 // 
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.
31 //
32 using System;
33 using System.Collections;
34 using System.ComponentModel;
35 using System.IO;
36 using System.Text;
37 using System.Xml;
38 using System.Xml.Schema;
39 using System.Xml.Serialization;
40 using Mono.Xml.XPath;
41
42 //using InternalBuilder = Mono.Xml.XPath.DTMXPathDocumentBuilder;
43 //using InternalDocument = Mono.Xml.XPath.DTMXPathDocument;
44 using InternalBuilder = Mono.Xml.XPath.DTMXPathDocumentBuilder2;
45 using InternalDocument = Mono.Xml.XPath.DTMXPathDocument2;
46
47 namespace System.Xml.XPath
48 {
49         public class XPathDocument : IXPathNavigable
50         {
51                 IXPathNavigable document;
52
53                 public XPathDocument (Stream stream)
54                 {
55                         XmlValidatingReader vr = new XmlValidatingReader (new XmlTextReader (stream));
56                         vr.ValidationType = ValidationType.None;
57                         Initialize (vr, XmlSpace.None);
58                 }
59
60                 public XPathDocument (string uri) 
61                         : this (uri, XmlSpace.None)
62                 {
63                 }
64
65                 public XPathDocument (TextReader textReader)
66                 {
67                         XmlValidatingReader vr = new XmlValidatingReader (new XmlTextReader (textReader));
68                         vr.ValidationType = ValidationType.None;
69                         Initialize (vr, XmlSpace.None);
70                 }
71
72                 public XPathDocument (XmlReader reader)
73                         : this (reader, XmlSpace.None)
74                 {
75                 }
76
77                 public XPathDocument (string uri, XmlSpace space)
78                 {
79                         XmlValidatingReader vr = null;
80                         try {
81                                 vr = new XmlValidatingReader (new XmlTextReader (uri));
82                                 vr.ValidationType = ValidationType.None;
83                                 Initialize (vr, space);
84                         } finally {
85                                 if (vr != null)
86                                         vr.Close ();
87                         }
88                 }
89
90                 public XPathDocument (XmlReader reader, XmlSpace space)
91                 {
92                         Initialize (reader, space);
93                 }
94
95                 private void Initialize (XmlReader reader, XmlSpace space)
96                 {
97                         document = new InternalBuilder (reader, space).CreateDocument ();
98                 }
99
100                 public XPathNavigator CreateNavigator ()
101                 {
102                         return document.CreateNavigator ();
103                 }
104         }
105 }
106
107