Welcome to mirror list, hosted at ThFree Co, Russian Federation.

SchemaElement.cs « SchemaObjectModel « EntityModel « Data « System « System.Data.Entity « referencesource « class « mcs - github.com/mono/mono.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 79be13fdd4ff42e914865cf90fb6b737b13da0f5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
//---------------------------------------------------------------------
// <copyright file="SchemaElement.cs" company="Microsoft">
//      Copyright (c) Microsoft Corporation.  All rights reserved.
// </copyright>
//
// @owner       Microsoft
// @backupOwner Microsoft
//---------------------------------------------------------------------

namespace System.Data.EntityModel.SchemaObjectModel
{
    using System;
    using System.Collections.Generic;
    using System.Data;
    using System.Data.Entity;
    using System.Data.Metadata.Edm;
    using System.Diagnostics;
    using System.Globalization;
    using System.IO;
    using System.Xml;
    using System.Xml.Linq;

    /// <summary>
    /// Summary description for SchemaElement.
    /// </summary>
    [DebuggerDisplay("Name={Name}")]
    internal abstract class SchemaElement
    {
        // see http://www.w3.org/TR/2006/REC-xml-names-20060816/
        internal const string XmlNamespaceNamespace = "http://www.w3.org/2000/xmlns/";


        #region Instance Fields
        private SchemaElement _parentElement = null;
        private Schema _schema = null;
        private int _lineNumber = 0;
        private int _linePosition = 0;
        private string _name = null;
        private DocumentationElement _documentation = null;

        private List<MetadataProperty> _otherContent;

        #endregion

        #region Static Fields
        /// <summary></summary>
        protected const int MaxValueVersionComponent = short.MaxValue;
        #endregion

        #region Public Properties
        /// <summary>
        /// 
        /// </summary>
        internal  int LineNumber
        {
            get
            {
                return _lineNumber;
            }
        }

        /// <summary>
        /// 
        /// </summary>
        internal  int LinePosition
        {
            get
            {
                return _linePosition;
            }
        }

        /// <summary>
        /// 
        /// </summary>
        public virtual string Name
        {
            get
            {
                return _name;
            }
            set
            {
                _name = value;
            }
        }

        /// <summary>
        /// 
        /// </summary>
        internal  DocumentationElement Documentation
        {
            get
            {
                return _documentation;
            }
            set
            {
                _documentation = value;
            }
        }

        /// <summary>
        /// 
        /// </summary>
        internal  SchemaElement ParentElement
        {
            get
            {
                return _parentElement;
            }
            private set
            {
                _parentElement = value;
            }
        }

        /// <summary>
        /// 
        /// </summary>
        internal Schema Schema
        {
            get
            {
                return _schema;
            }
            set
            {
                _schema = value;
            }
        }
        
        /// <summary>
        /// 
        /// </summary>
        public  virtual string FQName
        {
            get
            {
                return Name;
            }
        }

        /// <summary>
        /// 
        /// </summary>
        public virtual string Identity
        {
            get
            {
                return Name;
            }
        }

       
        public List<MetadataProperty> OtherContent
        {
            get 
            {
                if (_otherContent == null)
                {
                    _otherContent = new List<MetadataProperty>();
                }

                return _otherContent; 
            }
        }
        #endregion

        #region Internal Methods
        /// <summary>
        /// Validates this element and its children
        /// </summary>
        
        internal virtual void Validate()
        {
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="errorCode"></param>
        /// <param name="severity"></param>
        /// <param name="lineNumber"></param>
        /// <param name="linePosition"></param>
        /// <param name="message"></param>
        internal void AddError( ErrorCode errorCode, EdmSchemaErrorSeverity severity, int lineNumber, int linePosition, object message )
        {
            AddError(errorCode,severity,SchemaLocation,lineNumber,linePosition,message);
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="errorCode"></param>
        /// <param name="severity"></param>
        /// <param name="reader"></param>
        /// <param name="message"></param>
        internal void AddError( ErrorCode errorCode, EdmSchemaErrorSeverity severity, XmlReader reader, object message )
        {
            int lineNumber;
            int linePosition;
            GetPositionInfo(reader, out lineNumber, out linePosition);
            AddError(errorCode,severity,SchemaLocation,lineNumber,linePosition,message);
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="errorCode"></param>
        /// <param name="severity"></param>
        /// <param name="message"></param>
        internal void AddError( ErrorCode errorCode, EdmSchemaErrorSeverity severity, object message )
        {
            AddError(errorCode,severity,SchemaLocation,LineNumber,LinePosition,message);
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="errorCode"></param>
        /// <param name="severity"></param>
        /// <param name="element"></param>
        /// <param name="message"></param>
        internal void AddError( ErrorCode errorCode, EdmSchemaErrorSeverity severity, SchemaElement element, object message )
        {
            AddError(errorCode,severity,element.Schema.Location,element.LineNumber,element.LinePosition,message);
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="reader"></param>
        /// <returns></returns>
        internal void Parse(XmlReader reader)
        {
            GetPositionInfo(reader);

            bool hasEndElement = !reader.IsEmptyElement;

            Debug.Assert(reader.NodeType == XmlNodeType.Element);
            for ( bool more = reader.MoveToFirstAttribute(); more; more = reader.MoveToNextAttribute() )
            {
                ParseAttribute(reader);
            }
            HandleAttributesComplete();

            bool done = !hasEndElement;
            bool skipToNextElement = false;
            while ( !done )
            {
                if ( skipToNextElement )
                {
                    skipToNextElement = false;
                    reader.Skip();
                    if ( reader.EOF )
                        break;
                }
                else
                {
                    if ( !reader.Read() )
                        break;
                }
                switch ( reader.NodeType )
                {
                    case XmlNodeType.Element:
                        skipToNextElement = ParseElement(reader);
                        break;

                    case XmlNodeType.EndElement:
                    {
                        done = true;
                        break;
                    }

                    case XmlNodeType.CDATA:
                    case XmlNodeType.Text:
                    case XmlNodeType.SignificantWhitespace:
                        ParseText(reader);
                        break;

                        // we ignore these childless elements
                    case XmlNodeType.Whitespace:
                    case XmlNodeType.XmlDeclaration:
                    case XmlNodeType.Comment:
                    case XmlNodeType.Notation:
                    case XmlNodeType.ProcessingInstruction:
                    {
                        break;
                    }

                        // we ignore these elements that can have children
                    case XmlNodeType.DocumentType:
                    case XmlNodeType.EntityReference:
                    {
                        skipToNextElement = true;
                        break;
                    }

                    default:
                    {
                        AddError( ErrorCode.UnexpectedXmlNodeType, EdmSchemaErrorSeverity.Error, reader,
                            System.Data.Entity.Strings.UnexpectedXmlNodeType(reader.NodeType));
                        skipToNextElement = true;
                        break;
                    }
                }
            }
            HandleChildElementsComplete();
            if ( reader.EOF && reader.Depth > 0 )
            {
                AddError( ErrorCode.MalformedXml, EdmSchemaErrorSeverity.Error, 0, 0,
                    System.Data.Entity.Strings.MalformedXml(LineNumber,LinePosition));
            }
        }

        /// <summary>
        /// Set the current line number and position for an XmlReader
        /// </summary>
        /// <param name="reader">the reader whose position is desired</param>
        internal void GetPositionInfo(XmlReader reader)
        {
            GetPositionInfo(reader,out _lineNumber,out _linePosition);
        }

        /// <summary>
        /// Get the current line number and position for an XmlReader
        /// </summary>
        /// <param name="reader">the reader whose position is desired</param>
        /// <param name="lineNumber">the line number</param>
        /// <param name="linePosition">the line position</param>
        internal static void GetPositionInfo(XmlReader reader, out int lineNumber, out int linePosition)
        {
            IXmlLineInfo xmlLineInfo = reader as IXmlLineInfo;
            if ( xmlLineInfo != null && xmlLineInfo.HasLineInfo() )
            {
                lineNumber = xmlLineInfo.LineNumber;
                linePosition = xmlLineInfo.LinePosition;
            }
            else
            {
                lineNumber = 0;
                linePosition = 0;
            }
        }
        
        /// <summary>
        /// 
        /// </summary>
        internal virtual void ResolveTopLevelNames()
        {
        }
        internal virtual void ResolveSecondLevelNames()
        {
        }
        #endregion

        #region Protected Methods

        /// <summary>
        /// 
        /// </summary>
        /// <param name="parentElement"></param>
        internal SchemaElement(SchemaElement parentElement)
        {
            if ( parentElement != null )
            {
                ParentElement = parentElement;
                for ( SchemaElement element = parentElement; element != null; element = element.ParentElement )
                {
                    Schema schema = element as Schema;
                    if ( schema != null )
                    {
                        Schema = schema;
                        break;
                    }
                }
                
                if (Schema == null)
                {
                    throw EntityUtil.InvalidOperation(System.Data.Entity.Strings.AllElementsMustBeInSchema);
                }
            }
        }

        internal SchemaElement(SchemaElement parentElement, string name)
            : this(parentElement)
        {
            _name = name;
        }

        /// <summary>
        /// 
        /// </summary>
        protected virtual void HandleAttributesComplete()
        {
        }

        /// <summary>
        /// 
        /// </summary>
        protected virtual void HandleChildElementsComplete()
        {
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="reader"></param>
        /// <param name="field"></param>
        /// <returns></returns>
        protected string HandleUndottedNameAttribute(XmlReader reader, string field)
        {
            string name = field;
            Debug.Assert(string.IsNullOrEmpty(field), string.Format(CultureInfo.CurrentCulture, "{0} is already defined", reader.Name));

            bool success = Utils.GetUndottedName(Schema, reader, out name);
            if ( !success )
                return name;

            return name;
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="reader"></param>
        /// <param name="field"></param>
        /// <param name="errorMessageId"></param>
        /// <returns></returns>
        protected ReturnValue<string> HandleDottedNameAttribute(XmlReader reader, string field, Func<object, string> errorFormat)
        {
            ReturnValue<string> returnValue = new ReturnValue<string>();
            Debug.Assert(string.IsNullOrEmpty(field), string.Format(CultureInfo.CurrentCulture, "{0} is already defined", reader.Name));

            string value;
            if ( !Utils.GetDottedName(Schema,reader,out value) )
                return returnValue;

            returnValue.Value = value;
            return returnValue;
        }

        /// <summary>
        /// Use to handle an attribute with an int data type
        /// </summary>
        /// <param name="reader">the reader positioned at the int attribute</param>
        /// <param name="field">The int field to be given the value found</param>
        /// <returns>true if an int value was successfuly extracted from the attribute, false otherwise.</returns>
        internal bool HandleIntAttribute(XmlReader reader, ref int field)
        {
            int value;
            if ( !Utils.GetInt(Schema, reader, out value) )
                return false;

            field = value;
            return true;
        }

        /// <summary>
        /// Use to handle an attribute with an int data type
        /// </summary>
        /// <param name="reader">the reader positioned at the int attribute</param>
        /// <param name="field">The int field to be given the value found</param>
        /// <returns>true if an int value was successfuly extracted from the attribute, false otherwise.</returns>
        internal bool HandleByteAttribute(XmlReader reader, ref byte field)
        {
            byte value;
            if ( !Utils.GetByte(Schema, reader, out value) )
                return false;

            field = value;
            return true;
        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="reader"></param>
        /// <param name="field"></param>
        /// <returns></returns>
        internal bool HandleBoolAttribute(XmlReader reader, ref bool field)
        {
            bool value;
            if ( !Utils.GetBool(Schema,reader,out value) )
                return false;

            field = value;
            return true;
        }

        /// <summary>
        /// Use this to jump through an element that doesn't need any processing
        /// </summary>
        /// <param name="reader">xml reader currently positioned at an element</param>
        protected virtual void SkipThroughElement(XmlReader reader)
        {
            Debug.Assert(reader != null);
            Parse(reader);
        }

        protected void SkipElement(XmlReader reader)
        {
            using (XmlReader subtree = reader.ReadSubtree())
            {
                while (subtree.Read()) ;
            }
        }

        #endregion

        #region Protected Properties
        /// <summary>
        /// 
        /// </summary>
        protected string SchemaLocation
        {
            get
            {
                if ( Schema != null )
                    return Schema.Location;
                return null;
            }
        }

        protected virtual bool HandleText(XmlReader reader)
        {
            return false;
        }

        internal virtual SchemaElement Clone(SchemaElement parentElement)
        {
            throw Error.NotImplemented();
        }
        #endregion

        #region Private Methods
        /// <summary>
        /// 
        /// </summary>
        /// <param name="reader"></param>
        /// <returns></returns>
        private void HandleDocumentationElement(XmlReader reader)
        {
            Documentation = new DocumentationElement(this);
            Documentation.Parse(reader);
        }
        
        /// <summary>
        /// 
        /// </summary>
        /// <param name="reader"></param>
        protected virtual void HandleNameAttribute(XmlReader reader)
        {
            Name = HandleUndottedNameAttribute(reader, Name);
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="errorCode"></param>
        /// <param name="severity"></param>
        /// <param name="source"></param>
        /// <param name="lineNumber"></param>
        /// <param name="linePosition"></param>
        /// <param name="message"></param>
        private void AddError( ErrorCode errorCode, EdmSchemaErrorSeverity severity, string sourceLocation, int lineNumber, int linePosition, object message )
        {
            EdmSchemaError error = null;
            string messageString = message as string;
            if ( messageString != null )
                error = new EdmSchemaError( messageString, (int)errorCode, severity, sourceLocation, lineNumber, linePosition );
            else
            {
                Exception ex = message as Exception;
                if ( ex != null )
                    error = new EdmSchemaError( ex.Message, (int)errorCode, severity, sourceLocation, lineNumber, linePosition, ex );
                else
                    error = new EdmSchemaError( message.ToString(), (int)errorCode, severity, sourceLocation, lineNumber, linePosition );
            }
            Schema.AddError(error);
        }

        /// <summary>
        /// Call handler for the current attribute
        /// </summary>
        /// <param name="reader">XmlReader positioned at the attribute</param>
        private void ParseAttribute(XmlReader reader)
        {
#if false
            // the attribute value is schema invalid, just skip it; this avoids some duplicate errors at the expense of better error messages...
            if ( reader.SchemaInfo != null && reader.SchemaInfo.Validity == System.Xml.Schema.XmlSchemaValidity.Invalid )
                continue;
#endif
            string attributeNamespace = reader.NamespaceURI;
            if (attributeNamespace == XmlConstants.AnnotationNamespace 
                && reader.LocalName == XmlConstants.UseStrongSpatialTypes
                && !ProhibitAttribute(attributeNamespace, reader.LocalName) 
                && HandleAttribute(reader))
            {
                return;
            }
            else if (!Schema.IsParseableXmlNamespace(attributeNamespace, true))
            {
                AddOtherContent(reader);                
            }
            else if (!ProhibitAttribute(attributeNamespace, reader.LocalName)&&
                     HandleAttribute(reader))
            {
                return;
            }
            else if (reader.SchemaInfo == null || reader.SchemaInfo.Validity != System.Xml.Schema.XmlSchemaValidity.Invalid)
            {
                // there's no handler for (namespace,name) and there wasn't a validation error. 
                // Report an error of our own if the node is in no namespace or if it is in one of our xml schemas tartget namespace.
                if (string.IsNullOrEmpty(attributeNamespace) || Schema.IsParseableXmlNamespace(attributeNamespace, true))
                {
                    AddError(ErrorCode.UnexpectedXmlAttribute, EdmSchemaErrorSeverity.Error, reader, System.Data.Entity.Strings.UnexpectedXmlAttribute(reader.Name));
                }
            }
        }

        protected virtual bool ProhibitAttribute(string namespaceUri, string localName)
        {
            return false;
        }

        /// <summary>
        /// This overload assumes the default namespace
        /// </summary>
        /// <param name="reader"></param>
        /// <param name="localName"></param>
        /// <returns></returns>
        internal static bool CanHandleAttribute(XmlReader reader, string localName)
        {
            Debug.Assert(reader.NamespaceURI != null);
            return reader.NamespaceURI.Length == 0 && reader.LocalName == localName;
        }

        protected virtual bool HandleAttribute(XmlReader reader)
        {
            if(CanHandleAttribute(reader, XmlConstants.Name))
            {
                HandleNameAttribute(reader);
                return true;
            }

            return false;
        }

        private bool AddOtherContent(XmlReader reader)
        {
            int lineNumber;
            int linePosition;
            GetPositionInfo(reader, out lineNumber, out linePosition);

            MetadataProperty property;
            if (reader.NodeType == XmlNodeType.Element)
            {

                if (this._schema.SchemaVersion == XmlConstants.EdmVersionForV1 ||
                    this._schema.SchemaVersion == XmlConstants.EdmVersionForV1_1)
                {
                    // skip this element
                    // we don't support element annotations in v1 and v1.1
                    return true;
                }

                // in V1 and V1.1 the codegen can only appear as the attribute annotation and we want to maintain
                // the same behavior for V2, thus we throw if we encounter CodeGen namespace 
                // in structural annotation in V2 and furthur version
                if (this._schema.SchemaVersion >= XmlConstants.EdmVersionForV2 
                    && reader.NamespaceURI == XmlConstants.CodeGenerationSchemaNamespace)
                {
                    Debug.Assert(
                        XmlConstants.SchemaVersionLatest == XmlConstants.EdmVersionForV3, 
                        "Please add checking for the latest namespace");

                    AddError(ErrorCode.NoCodeGenNamespaceInStructuralAnnotation, EdmSchemaErrorSeverity.Error, lineNumber, linePosition, Strings.NoCodeGenNamespaceInStructuralAnnotation(XmlConstants.CodeGenerationSchemaNamespace));
                    return true;
                }

                Debug.Assert(
                        !Schema.IsParseableXmlNamespace(reader.NamespaceURI, false),
                        "Structural annotation cannot use any edm reserved namespaces");

                // using this subtree aproach because when I call 
                // reader.ReadOuterXml() it positions me at the Node beyond
                // the end of the node I am starting on
                // which doesn't work with the parsing logic
                using (XmlReader subtree = reader.ReadSubtree())
                {
                    subtree.Read();
                    XElement element = XElement.Load(new StringReader(subtree.ReadOuterXml()));

                    property = CreateMetadataPropertyFromOtherNamespaceXmlArtifact(element.Name.NamespaceName, element.Name.LocalName, element);
                }
            }
            else
            {
                if (reader.NamespaceURI == XmlNamespaceNamespace)
                {
                    // we don't bring in namespace definitions
                    return true;
                }

                Debug.Assert(reader.NodeType == XmlNodeType.Attribute, "called an attribute function when not on an attribute");
                property = CreateMetadataPropertyFromOtherNamespaceXmlArtifact(reader.NamespaceURI, reader.LocalName, reader.Value);
            }

            if (!OtherContent.Exists(mp => mp.Identity == property.Identity))
            {
                OtherContent.Add(property);
            }
            else
            {
                AddError(ErrorCode.AlreadyDefined, EdmSchemaErrorSeverity.Error, lineNumber, linePosition, Strings.DuplicateAnnotation(property.Identity, this.FQName));
            }
            return false;
        }

        internal static MetadataProperty CreateMetadataPropertyFromOtherNamespaceXmlArtifact(string xmlNamespaceUri, string artifactName, object value)
        {
            MetadataProperty property;
            property = new MetadataProperty(xmlNamespaceUri + ":" + artifactName,
                                       TypeUsage.Create(EdmProviderManifest.Instance.GetPrimitiveType(PrimitiveTypeKind.String)),
                                       value);
            return property;
        }

        /// <summary>
        /// Call handler for the current element
        /// </summary>
        /// <param name="reader">XmlReader positioned at the element</param>
        /// <returns>true if element content should be skipped</returns>
        private bool ParseElement(XmlReader reader)
        {
            string elementNamespace = reader.NamespaceURI;
            // for schema element that right under the schema, we just ignore them, since schema does not
            // have metadataproperties
            if (!Schema.IsParseableXmlNamespace(elementNamespace, true) && this.ParentElement != null)
            {
                return AddOtherContent(reader);
            }
            if (HandleElement(reader))
            {
                return false;
            }
            else
            {

                // we need to report an error if the namespace for this element is a target namespace for the xml schemas we are parsing against.
                // otherwise we assume that this is either a valid 'any' element or that the xsd validator has generated an error
                if (string.IsNullOrEmpty(elementNamespace) || Schema.IsParseableXmlNamespace(reader.NamespaceURI, false))
                {
                    AddError(ErrorCode.UnexpectedXmlElement, EdmSchemaErrorSeverity.Error, reader, System.Data.Entity.Strings.UnexpectedXmlElement(reader.Name));
                }
                return true;
            }
        }

        protected bool CanHandleElement(XmlReader reader, string localName)
        {
            return reader.NamespaceURI == Schema.SchemaXmlNamespace && reader.LocalName == localName;
        }

        protected virtual bool HandleElement(XmlReader reader)
        {
            if (CanHandleElement(reader, XmlConstants.Documentation))
            {
                HandleDocumentationElement(reader);
                return true;
            }

            return false;
        }

        /// <summary>
        /// Handle text data.
        /// </summary>
        /// <param name="reader">XmlReader positioned at Text, CData, or SignificantWhitespace </param>
        private void ParseText(XmlReader reader)
        {
            if (HandleText(reader))
            {
                return;
            }
            else if (reader.Value != null && reader.Value.Trim().Length == 0)
            {
                // just ignore this text.  Don't add an error, since the value is just whitespace.
            }
            else
            {
                AddError( ErrorCode.TextNotAllowed, EdmSchemaErrorSeverity.Error, reader, System.Data.Entity.Strings.TextNotAllowed(reader.Value ) );
            }
        }
        #endregion

        [Conditional("DEBUG")]
        internal static void AssertReaderConsidersSchemaInvalid(XmlReader reader)
        {
            Debug.Assert(reader.SchemaInfo == null ||
                         reader.SchemaInfo.Validity != System.Xml.Schema.XmlSchemaValidity.Valid, "The xsd should see this as not acceptable");
        }

    }
}