2 // Mono.Xml.XmlFilterReader.cs
5 // Atsushi Enomoto <atsushi@ximian.com>
7 // Copyright (c) 2004 Novell Inc. All rights reserved
9 // Permission is hereby granted, free of charge, to any person obtaining
10 // a copy of this software and associated documentation files (the
11 // "Software"), to deal in the Software without restriction, including
12 // without limitation the rights to use, copy, modify, merge, publish,
13 // distribute, sublicense, and/or sell copies of the Software, and to
14 // permit persons to whom the Software is furnished to do so, subject to
15 // the following conditions:
17 // The above copyright notice and this permission notice shall be
18 // included in all copies or substantial portions of the Software.
20 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
21 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
22 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
23 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
24 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
25 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
26 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
30 // Similar to SAX DefaultHandler
39 internal class XmlFilterReader
: XmlReader
, IXmlLineInfo
42 XmlReaderSettings settings
;
43 IXmlLineInfo lineInfo
;
45 public XmlFilterReader (XmlReader reader
, XmlReaderSettings settings
)
48 this.settings
= settings
;
49 this.lineInfo
= reader
as IXmlLineInfo
;
53 // This is the only one non-overriden property.
54 public XmlReader Reader
{
55 get { return reader; }
58 public int LineNumber
{
59 get { return lineInfo != null ? lineInfo.LineNumber : 0; }
62 public int LinePosition
{
63 get { return lineInfo != null ? lineInfo.LinePosition : 0; }
66 public override XmlNodeType NodeType
68 get { return reader.NodeType; }
71 public override string Name
{
72 get { return reader.Name; }
75 public override string LocalName
{
76 get { return reader.LocalName; }
79 public override string NamespaceURI
{
80 get { return reader.NamespaceURI; }
83 public override string Prefix
{
84 get { return reader.Prefix; }
87 public override bool HasValue
{
88 get { return reader.HasValue; }
91 public override int Depth
{
92 get { return reader.Depth; }
95 public override string Value
{
96 get { return reader.Value; }
99 public override string BaseURI
{
100 get { return reader.BaseURI; }
103 public override bool IsEmptyElement
{
104 get { return reader.IsEmptyElement; }
107 public override bool IsDefault
{
108 get { return reader.IsDefault; }
111 public override char QuoteChar
{
112 get { return reader.QuoteChar; }
115 public override string XmlLang
{
116 get { return reader.XmlLang; }
119 public override XmlSpace XmlSpace
{
120 get { return reader.XmlSpace; }
123 public override int AttributeCount
{
124 get { return reader.AttributeCount; }
127 public override string this [int i
] {
128 get { return reader [i]; }
131 public override string this [string name
] {
132 get { return reader [name]; }
135 public override string this [string localName
, string namespaceURI
] {
136 get { return reader [localName, namespaceURI]; }
139 public override bool EOF
{
140 get { return reader.EOF; }
143 public override ReadState ReadState
{
144 get { return reader.ReadState; }
147 public override XmlNameTable NameTable
{
148 get { return reader.NameTable; }
154 public override string GetAttribute (string name
)
156 return reader
.GetAttribute (name
);
159 public override string GetAttribute (string localName
, string namespaceURI
)
161 return reader
.GetAttribute (localName
, namespaceURI
);
164 public override string GetAttribute (int i
)
166 return reader
.GetAttribute (i
);
169 public bool HasLineInfo ()
171 return lineInfo
!= null ? lineInfo
.HasLineInfo () : false;
174 public override bool MoveToAttribute (string name
)
176 return reader
.MoveToAttribute (name
);
179 public override bool MoveToAttribute (string localName
, string namespaceURI
)
181 return reader
.MoveToAttribute (localName
, namespaceURI
);
184 public override void MoveToAttribute (int i
)
186 reader
.MoveToAttribute (i
);
189 public override bool MoveToFirstAttribute ()
191 return reader
.MoveToFirstAttribute ();
194 public override bool MoveToNextAttribute ()
196 return reader
.MoveToNextAttribute ();
199 public override bool MoveToElement ()
201 return reader
.MoveToElement ();
204 public override void Close ()
209 public override bool Read ()
214 if (reader
.NodeType
== XmlNodeType
.DocumentType
&& settings
.ProhibitDtd
)
215 throw new XmlException ("Document Type Definition (DTD) is prohibited in this XML reader.");
217 if (reader
.NodeType
== XmlNodeType
.Whitespace
&&
218 settings
.IgnoreWhitespace
)
220 if (reader
.NodeType
== XmlNodeType
.ProcessingInstruction
&&
221 settings
.IgnoreProcessingInstructions
)
223 if (reader
.NodeType
== XmlNodeType
.Comment
&&
224 settings
.IgnoreComments
)
230 public override string ReadString ()
232 return reader
.ReadString ();
237 public override string ReadInnerXml ()
239 return ReadInnerXmlInternal ();
242 public override string ReadOuterXml ()
244 return ReadOuterXmlInternal ();
248 public override string LookupNamespace (string prefix
)
250 return reader
.LookupNamespace (prefix
);
253 public override void ResolveEntity ()
255 reader
.ResolveEntity ();
258 public override bool ReadAttributeValue () {
259 return reader
.ReadAttributeValue ();