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
36 using System
.Xml
.Schema
;
40 internal class XmlFilterReader
: XmlReader
, IXmlLineInfo
43 XmlReaderSettings settings
;
44 IXmlLineInfo lineInfo
;
46 public XmlFilterReader (XmlReader reader
, XmlReaderSettings settings
)
49 this.settings
= settings
.Clone ();
50 this.lineInfo
= reader
as IXmlLineInfo
;
56 public override bool CanReadBinaryContent
{
57 get { return reader.CanReadBinaryContent; }
60 public override bool CanReadValueChunk
{
61 get { return reader.CanReadValueChunk; }
65 // This is the only one non-overriden property.
66 public XmlReader Reader
{
67 get { return reader; }
70 public int LineNumber
{
71 get { return lineInfo != null ? lineInfo.LineNumber : 0; }
74 public int LinePosition
{
75 get { return lineInfo != null ? lineInfo.LinePosition : 0; }
78 public override XmlNodeType NodeType
80 get { return reader.NodeType; }
83 public override string Name
{
84 get { return reader.Name; }
87 public override string LocalName
{
88 get { return reader.LocalName; }
91 public override string NamespaceURI
{
92 get { return reader.NamespaceURI; }
95 public override string Prefix
{
96 get { return reader.Prefix; }
99 public override bool HasValue
{
100 get { return reader.HasValue; }
103 public override int Depth
{
104 get { return reader.Depth; }
107 public override string Value
{
108 get { return reader.Value; }
111 public override string BaseURI
{
112 get { return reader.BaseURI; }
115 public override bool IsEmptyElement
{
116 get { return reader.IsEmptyElement; }
119 public override bool IsDefault
{
120 get { return reader.IsDefault; }
123 public override char QuoteChar
{
124 get { return reader.QuoteChar; }
127 public override string XmlLang
{
128 get { return reader.XmlLang; }
131 public override XmlSpace XmlSpace
{
132 get { return reader.XmlSpace; }
135 public override int AttributeCount
{
136 get { return reader.AttributeCount; }
139 public override string this [int i
] {
140 get { return reader [i]; }
143 public override string this [string name
] {
144 get { return reader [name]; }
147 public override string this [string localName
, string namespaceURI
] {
148 get { return reader [localName, namespaceURI]; }
151 public override bool EOF
{
152 get { return reader.EOF; }
155 public override ReadState ReadState
{
156 get { return reader.ReadState; }
159 public override XmlNameTable NameTable
{
160 get { return reader.NameTable; }
164 public override IXmlSchemaInfo SchemaInfo
{
165 get { return reader.SchemaInfo; }
169 public override XmlReaderSettings Settings
{
170 get { return settings; }
176 public override string GetAttribute (string name
)
178 return reader
.GetAttribute (name
);
181 public override string GetAttribute (string localName
, string namespaceURI
)
183 return reader
.GetAttribute (localName
, namespaceURI
);
186 public override string GetAttribute (int i
)
188 return reader
.GetAttribute (i
);
191 public bool HasLineInfo ()
193 return lineInfo
!= null ? lineInfo
.HasLineInfo () : false;
196 public override bool MoveToAttribute (string name
)
198 return reader
.MoveToAttribute (name
);
201 public override bool MoveToAttribute (string localName
, string namespaceURI
)
203 return reader
.MoveToAttribute (localName
, namespaceURI
);
206 public override void MoveToAttribute (int i
)
208 reader
.MoveToAttribute (i
);
211 public override bool MoveToFirstAttribute ()
213 return reader
.MoveToFirstAttribute ();
216 public override bool MoveToNextAttribute ()
218 return reader
.MoveToNextAttribute ();
221 public override bool MoveToElement ()
223 return reader
.MoveToElement ();
226 public override void Close ()
228 if (settings
.CloseInput
)
232 public override bool Read ()
237 if (reader
.NodeType
== XmlNodeType
.DocumentType
&& settings
.ProhibitDtd
)
238 throw new XmlException ("Document Type Definition (DTD) is prohibited in this XML reader.");
240 if (reader
.NodeType
== XmlNodeType
.Whitespace
&&
241 settings
.IgnoreWhitespace
)
243 if (reader
.NodeType
== XmlNodeType
.ProcessingInstruction
&&
244 settings
.IgnoreProcessingInstructions
)
246 if (reader
.NodeType
== XmlNodeType
.Comment
&&
247 settings
.IgnoreComments
)
253 public override string ReadString ()
255 return reader
.ReadString ();
260 public override string ReadInnerXml ()
262 return ReadInnerXmlInternal ();
265 public override string ReadOuterXml ()
267 return ReadOuterXmlInternal ();
271 public override string LookupNamespace (string prefix
)
273 return reader
.LookupNamespace (prefix
);
276 public override void ResolveEntity ()
278 reader
.ResolveEntity ();
281 public override bool ReadAttributeValue () {
282 return reader
.ReadAttributeValue ();