1 //------------------------------------------------------------------------------
2 // <copyright file="XmlValidatingReader.cs" company="Microsoft">
3 // Copyright (c) Microsoft Corporation. All rights reserved.
5 // <owner current="true" primary="true">Microsoft</owner>
6 //------------------------------------------------------------------------------
11 using System.Xml.Schema;
12 using System.Collections;
13 using System.Collections.Generic;
14 using System.Security.Permissions;
18 [PermissionSetAttribute( SecurityAction.InheritanceDemand, Name = "FullTrust" )]
19 [Obsolete("Use XmlReader created by XmlReader.Create() method using appropriate XmlReaderSettings instead. http://go.microsoft.com/fwlink/?linkid=14202")]
20 public class XmlValidatingReader : XmlReader, IXmlLineInfo, IXmlNamespaceResolver {
24 XmlValidatingReaderImpl impl;
28 public XmlValidatingReader( XmlReader reader ) {
29 impl = new XmlValidatingReaderImpl( reader );
30 impl.OuterReader = this;
33 public XmlValidatingReader( string xmlFragment, XmlNodeType fragType, XmlParserContext context ) {
34 if (xmlFragment == null) {
35 throw new ArgumentNullException("xmlFragment");
37 impl = new XmlValidatingReaderImpl( xmlFragment, fragType, context );
38 impl.OuterReader = this;
41 public XmlValidatingReader( Stream xmlFragment, XmlNodeType fragType, XmlParserContext context ) {
42 if (xmlFragment == null) {
43 throw new ArgumentNullException("xmlFragment");
45 impl = new XmlValidatingReaderImpl(xmlFragment, fragType, context);
46 impl.OuterReader = this;
52 public override XmlNodeType NodeType {
53 get { return impl.NodeType; }
56 public override string Name {
57 get { return impl.Name; }
60 public override string LocalName {
61 get { return impl.LocalName; }
64 public override string NamespaceURI {
65 get { return impl.NamespaceURI; }
68 public override string Prefix {
69 get { return impl.Prefix; }
72 public override bool HasValue {
73 get { return impl.HasValue; }
76 public override string Value {
77 get { return impl.Value; }
80 public override int Depth {
81 get { return impl.Depth; }
84 public override string BaseURI {
85 get { return impl.BaseURI; }
88 public override bool IsEmptyElement {
89 get { return impl.IsEmptyElement; }
92 public override bool IsDefault {
93 get { return impl.IsDefault; }
96 public override char QuoteChar {
97 get { return impl.QuoteChar; }
100 public override XmlSpace XmlSpace {
101 get { return impl.XmlSpace; }
104 public override string XmlLang {
105 get { return impl.XmlLang; }
108 // XmlTextReader does not override SchemaInfo, ValueType and ReadTypeValue
110 public override int AttributeCount { get { return impl.AttributeCount; } }
112 public override string GetAttribute( string name ) {
113 return impl.GetAttribute( name );
116 public override string GetAttribute( string localName, string namespaceURI ) {
117 return impl.GetAttribute( localName, namespaceURI );
120 public override string GetAttribute( int i ) {
121 return impl.GetAttribute( i );
124 public override bool MoveToAttribute( string name ) {
125 return impl.MoveToAttribute( name );
128 public override bool MoveToAttribute( string localName, string namespaceURI ) {
129 return impl.MoveToAttribute( localName, namespaceURI );
132 public override void MoveToAttribute( int i ) {
133 impl.MoveToAttribute( i );
136 public override bool MoveToFirstAttribute() {
137 return impl.MoveToFirstAttribute();
140 public override bool MoveToNextAttribute() {
141 return impl.MoveToNextAttribute();
144 public override bool MoveToElement() {
145 return impl.MoveToElement();
148 public override bool ReadAttributeValue() {
149 return impl.ReadAttributeValue();
152 public override bool Read() {
156 public override bool EOF {
157 get { return impl.EOF; }
160 public override void Close() {
164 public override ReadState ReadState {
165 get { return impl.ReadState; }
168 public override XmlNameTable NameTable {
169 get { return impl.NameTable; }
172 public override String LookupNamespace( String prefix ) {
173 string ns = impl.LookupNamespace( prefix );
174 if ( ns != null && ns.Length == 0 ) {
180 public override bool CanResolveEntity {
184 public override void ResolveEntity() {
185 impl.ResolveEntity();
188 // Binary content access methods
189 public override bool CanReadBinaryContent {
193 public override int ReadContentAsBase64( byte[] buffer, int index, int count ) {
194 return impl.ReadContentAsBase64( buffer, index, count );
197 public override int ReadElementContentAsBase64( byte[] buffer, int index, int count ) {
198 return impl.ReadElementContentAsBase64( buffer, index, count );
201 public override int ReadContentAsBinHex( byte[] buffer, int index, int count ) {
202 return impl.ReadContentAsBinHex( buffer, index, count );
205 public override int ReadElementContentAsBinHex( byte[] buffer, int index, int count ) {
206 return impl.ReadElementContentAsBinHex( buffer, index, count );
209 // Overriden helper methods
211 public override string ReadString() {
212 impl.MoveOffEntityReference();
213 return base.ReadString();
217 // IXmlLineInfo members
219 public bool HasLineInfo() { return true; }
221 public int LineNumber { get { return impl.LineNumber; } }
223 public int LinePosition { get { return impl.LinePosition; } }
226 // IXmlNamespaceResolver members
228 IDictionary<string,string> IXmlNamespaceResolver.GetNamespacesInScope( XmlNamespaceScope scope ) {
229 return impl.GetNamespacesInScope( scope );
232 string IXmlNamespaceResolver.LookupNamespace(string prefix) {
233 return impl.LookupNamespace( prefix );
236 string IXmlNamespaceResolver.LookupPrefix( string namespaceName ) {
237 return impl.LookupPrefix( namespaceName );
241 // XmlValidatingReader
243 public event ValidationEventHandler ValidationEventHandler {
244 add { impl.ValidationEventHandler += value; }
245 remove { impl.ValidationEventHandler -= value; }
248 public object SchemaType {
249 get { return impl.SchemaType; }
252 public XmlReader Reader {
253 get { return impl.Reader; }
256 public ValidationType ValidationType {
257 get { return impl.ValidationType; }
258 set { impl.ValidationType = value; }
261 public XmlSchemaCollection Schemas {
262 get { return impl.Schemas; }
265 public EntityHandling EntityHandling {
266 get { return impl.EntityHandling; }
267 set { impl.EntityHandling = value; }
270 public XmlResolver XmlResolver {
271 set { impl.XmlResolver = value; }
274 public bool Namespaces {
275 get { return impl.Namespaces; }
276 set { impl.Namespaces = value; }
279 public object ReadTypedValue() {
280 return impl.ReadTypedValue();
283 public Encoding Encoding {
284 get { return impl.Encoding; }
287 // Internal helper methods
289 internal XmlValidatingReaderImpl Impl {
293 internal override IDtdInfo DtdInfo {
294 get { return impl.DtdInfo; }