Code:
/ 4.0 / 4.0 / untmp / DEVDIV_TFS / Dev10 / Releases / RTMRel / ndp / fx / src / Xml / System / Xml / schema / SchemaInfo.cs / 1305376 / SchemaInfo.cs
//------------------------------------------------------------------------------ //// Copyright (c) Microsoft Corporation. All rights reserved. // //[....] //----------------------------------------------------------------------------- using System; using System.Xml; using System.Diagnostics; using System.Collections.Generic; namespace System.Xml.Schema { #if !SILVERLIGHT internal enum AttributeMatchState { AttributeFound, AnyIdAttributeFound, UndeclaredElementAndAttribute, UndeclaredAttribute, AnyAttributeLax, AnyAttributeSkip, ProhibitedAnyAttribute, ProhibitedAttribute, AttributeNameMismatch, ValidateAttributeInvalidCall, } #endif internal class SchemaInfo : IDtdInfo { DictionaryelementDecls = new Dictionary (); Dictionary undeclaredElementDecls = new Dictionary (); Dictionary generalEntities; Dictionary parameterEntities; XmlQualifiedName docTypeName = XmlQualifiedName.Empty; string internalDtdSubset = string.Empty; bool hasNonCDataAttributes = false; bool hasDefaultAttributes = false; #if !SILVERLIGHT Dictionary targetNamespaces = new Dictionary (); Dictionary attributeDecls = new Dictionary (); int errorCount; SchemaType schemaType; Dictionary elementDeclsByType = new Dictionary (); Dictionary notations; #endif internal SchemaInfo() { #if !SILVERLIGHT schemaType = SchemaType.None; #endif } public XmlQualifiedName DocTypeName { get { return docTypeName; } set { docTypeName = value; } } internal string InternalDtdSubset { get { return internalDtdSubset; } set { internalDtdSubset = value; } } internal Dictionary ElementDecls { get { return elementDecls; } } internal Dictionary UndeclaredElementDecls { get { return undeclaredElementDecls; } } internal Dictionary GeneralEntities { get { if (this.generalEntities == null) { this.generalEntities = new Dictionary (); } return this.generalEntities; } } internal Dictionary ParameterEntities { get { if (this.parameterEntities == null) { this.parameterEntities = new Dictionary (); } return this.parameterEntities; } } #if !SILVERLIGHT internal SchemaType SchemaType { get { return schemaType;} set { schemaType = value;} } internal Dictionary TargetNamespaces { get { return targetNamespaces; } } internal Dictionary ElementDeclsByType { get { return elementDeclsByType; } } internal Dictionary AttributeDecls { get { return attributeDecls; } } internal Dictionary Notations { get { if (this.notations == null) { this.notations = new Dictionary (); } return this.notations; } } internal int ErrorCount { get { return errorCount; } set { errorCount = value; } } internal SchemaElementDecl GetElementDecl(XmlQualifiedName qname) { SchemaElementDecl elemDecl; if (elementDecls.TryGetValue(qname, out elemDecl)) { return elemDecl; } return null; } internal SchemaElementDecl GetTypeDecl(XmlQualifiedName qname) { SchemaElementDecl elemDecl; if (elementDeclsByType.TryGetValue(qname, out elemDecl)) { return elemDecl; } return null; } internal XmlSchemaElement GetElement(XmlQualifiedName qname) { SchemaElementDecl ed = GetElementDecl(qname); if (ed != null) { return ed.SchemaElement; } return null; } internal XmlSchemaAttribute GetAttribute(XmlQualifiedName qname) { SchemaAttDef attdef = (SchemaAttDef)attributeDecls[qname]; if (attdef != null) { return attdef.SchemaAttribute; } return null; } internal XmlSchemaElement GetType(XmlQualifiedName qname) { SchemaElementDecl ed = GetElementDecl(qname); if (ed != null) { return ed.SchemaElement; } return null; } internal bool HasSchema(string ns) { return targetNamespaces.ContainsKey(ns); } internal bool Contains(string ns) { return targetNamespaces.ContainsKey(ns); } internal SchemaAttDef GetAttributeXdr(SchemaElementDecl ed, XmlQualifiedName qname) { SchemaAttDef attdef = null; if (ed != null) { attdef = ed.GetAttDef(qname);; if (attdef == null) { if (!ed.ContentValidator.IsOpen || qname.Namespace.Length == 0) { throw new XmlSchemaException(Res.Sch_UndeclaredAttribute, qname.ToString()); } if (!attributeDecls.TryGetValue(qname, out attdef) && targetNamespaces.ContainsKey(qname.Namespace)) { throw new XmlSchemaException(Res.Sch_UndeclaredAttribute, qname.ToString()); } } } return attdef; } internal SchemaAttDef GetAttributeXsd(SchemaElementDecl ed, XmlQualifiedName qname, XmlSchemaObject partialValidationType, out AttributeMatchState attributeMatchState) { SchemaAttDef attdef = null; attributeMatchState = AttributeMatchState.UndeclaredAttribute; if (ed != null) { attdef = ed.GetAttDef(qname); if (attdef != null) { attributeMatchState = AttributeMatchState.AttributeFound; return attdef; } XmlSchemaAnyAttribute any = ed.AnyAttribute; if (any != null) { if (!any.NamespaceList.Allows(qname)) { attributeMatchState = AttributeMatchState.ProhibitedAnyAttribute; } else if (any.ProcessContentsCorrect != XmlSchemaContentProcessing.Skip) { if (attributeDecls.TryGetValue(qname, out attdef)) { if (attdef.Datatype.TypeCode == XmlTypeCode.Id) { //anyAttribute match whose type is ID attributeMatchState = AttributeMatchState.AnyIdAttributeFound; } else { attributeMatchState = AttributeMatchState.AttributeFound; } } else if (any.ProcessContentsCorrect == XmlSchemaContentProcessing.Lax) { attributeMatchState = AttributeMatchState.AnyAttributeLax; } } else { attributeMatchState = AttributeMatchState.AnyAttributeSkip; } } else if (ed.ProhibitedAttributes.ContainsKey(qname)) { attributeMatchState = AttributeMatchState.ProhibitedAttribute; } } else if (partialValidationType != null) { XmlSchemaAttribute attr = partialValidationType as XmlSchemaAttribute; if (attr != null) { if (qname.Equals(attr.QualifiedName)) { attdef = attr.AttDef; attributeMatchState = AttributeMatchState.AttributeFound; } else { attributeMatchState = AttributeMatchState.AttributeNameMismatch; } } else { attributeMatchState = AttributeMatchState.ValidateAttributeInvalidCall; } } else { if (attributeDecls.TryGetValue(qname, out attdef)) { attributeMatchState = AttributeMatchState.AttributeFound; } else { attributeMatchState = AttributeMatchState.UndeclaredElementAndAttribute; } } return attdef; } internal SchemaAttDef GetAttributeXsd(SchemaElementDecl ed, XmlQualifiedName qname, ref bool skip) { AttributeMatchState attributeMatchState; SchemaAttDef attDef = GetAttributeXsd(ed, qname, null, out attributeMatchState); switch(attributeMatchState) { case AttributeMatchState.UndeclaredAttribute: throw new XmlSchemaException(Res.Sch_UndeclaredAttribute, qname.ToString()); case AttributeMatchState.ProhibitedAnyAttribute: case AttributeMatchState.ProhibitedAttribute: throw new XmlSchemaException(Res.Sch_ProhibitedAttribute, qname.ToString()); case AttributeMatchState.AttributeFound: case AttributeMatchState.AnyIdAttributeFound: case AttributeMatchState.AnyAttributeLax: case AttributeMatchState.UndeclaredElementAndAttribute: break; case AttributeMatchState.AnyAttributeSkip: skip = true; break; default: Debug.Assert(false); break; } return attDef; } internal void Add(SchemaInfo sinfo, ValidationEventHandler eventhandler) { if (schemaType == SchemaType.None) { schemaType = sinfo.SchemaType; } else if (schemaType != sinfo.SchemaType) { if (eventhandler != null) { eventhandler(this, new ValidationEventArgs(new XmlSchemaException(Res.Sch_MixSchemaTypes, string.Empty))); } return; } foreach(string tns in sinfo.TargetNamespaces.Keys) { if (!targetNamespaces.ContainsKey(tns)) { targetNamespaces.Add(tns, true); } } foreach(KeyValuePair entry in sinfo.elementDecls) { if (!elementDecls.ContainsKey(entry.Key)) { elementDecls.Add(entry.Key, entry.Value); } } foreach(KeyValuePair entry in sinfo.elementDeclsByType) { if (!elementDeclsByType.ContainsKey(entry.Key)) { elementDeclsByType.Add(entry.Key, entry.Value); } } foreach (SchemaAttDef attdef in sinfo.AttributeDecls.Values) { if (!attributeDecls.ContainsKey(attdef.Name)) { attributeDecls.Add(attdef.Name, attdef); } } foreach (SchemaNotation notation in sinfo.Notations.Values) { if (!Notations.ContainsKey(notation.Name.Name)) { Notations.Add(notation.Name.Name, notation); } } } #endif internal void Finish() { Dictionary elements = elementDecls; for ( int i = 0; i < 2; i++ ) { foreach ( SchemaElementDecl e in elements.Values ) { if ( e.HasNonCDataAttribute ) { hasNonCDataAttributes = true; } if ( e.DefaultAttDefs != null ) { hasDefaultAttributes = true; } } elements = undeclaredElementDecls; } } // // IDtdInfo interface // #region IDtdInfo Members bool IDtdInfo.HasDefaultAttributes { get { return hasDefaultAttributes; } } bool IDtdInfo.HasNonCDataAttributes { get { return hasNonCDataAttributes; } } IDtdAttributeListInfo IDtdInfo.LookupAttributeList(string prefix, string localName) { XmlQualifiedName qname = new XmlQualifiedName(prefix, localName); SchemaElementDecl elementDecl; if (!elementDecls.TryGetValue(qname, out elementDecl)) { undeclaredElementDecls.TryGetValue(qname, out elementDecl); } return elementDecl; } IEnumerable IDtdInfo.GetAttributeLists() { foreach (SchemaElementDecl elemDecl in elementDecls.Values) { IDtdAttributeListInfo eleDeclAsAttList = (IDtdAttributeListInfo)elemDecl; yield return eleDeclAsAttList; } } IDtdEntityInfo IDtdInfo.LookupEntity(string name) { if (generalEntities == null) { return null; } XmlQualifiedName qname = new XmlQualifiedName(name); SchemaEntity entity; if (generalEntities.TryGetValue(qname, out entity)) { return entity; } return null; } XmlQualifiedName IDtdInfo.Name { get { return docTypeName; } } string IDtdInfo.InternalDtdSubset { get { return internalDtdSubset; } } #endregion } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007.
Link Menu

This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- IPipelineRuntime.cs
- DataGridToolTip.cs
- FormatterConverter.cs
- Aggregates.cs
- Token.cs
- CompilerErrorCollection.cs
- SettingsAttributeDictionary.cs
- NativeMethodsOther.cs
- PointLight.cs
- AutoCompleteStringCollection.cs
- PrimitiveOperationFormatter.cs
- XpsFixedDocumentReaderWriter.cs
- OleDbSchemaGuid.cs
- GC.cs
- MULTI_QI.cs
- TablePatternIdentifiers.cs
- SqlConnectionHelper.cs
- ResourceReferenceExpression.cs
- GeneratedView.cs
- CompiledELinqQueryState.cs
- BeginStoryboard.cs
- AtomServiceDocumentSerializer.cs
- AdRotator.cs
- IOThreadTimer.cs
- SqlDataSourceTableQuery.cs
- PassportAuthenticationModule.cs
- Material.cs
- ObjectView.cs
- Trace.cs
- DisplayClaim.cs
- Resources.Designer.cs
- ButtonBaseAdapter.cs
- DesignerAdRotatorAdapter.cs
- ExceptionWrapper.cs
- EntityDataSourceChangingEventArgs.cs
- Accessible.cs
- XmlSchemaGroupRef.cs
- InheritedPropertyChangedEventArgs.cs
- ReadOnlyState.cs
- ProxyHelper.cs
- RelationshipEndCollection.cs
- ToolBar.cs
- BaseComponentEditor.cs
- JsonServiceDocumentSerializer.cs
- BlobPersonalizationState.cs
- XmlNavigatorFilter.cs
- ReadContentAsBinaryHelper.cs
- DetailsViewPageEventArgs.cs
- TraceInternal.cs
- FrameworkTemplate.cs
- RequestCacheValidator.cs
- DatePickerTextBox.cs
- VirtualPath.cs
- SecurityHeaderLayout.cs
- RuleProcessor.cs
- ToolStripDropTargetManager.cs
- RequestTimeoutManager.cs
- NodeFunctions.cs
- ContextMarshalException.cs
- UIElementCollection.cs
- TransformValueSerializer.cs
- ADMembershipProvider.cs
- AssemblyFilter.cs
- DropShadowEffect.cs
- ListViewGroupCollectionEditor.cs
- BindingManagerDataErrorEventArgs.cs
- DriveNotFoundException.cs
- LockCookie.cs
- InheritanceAttribute.cs
- HexParser.cs
- TextRange.cs
- Geometry3D.cs
- ControlUtil.cs
- FilterException.cs
- FigureParaClient.cs
- DataGridViewColumnHeaderCell.cs
- RijndaelManagedTransform.cs
- OleDbConnectionInternal.cs
- NumberSubstitution.cs
- VectorConverter.cs
- ServiceHttpHandlerFactory.cs
- PingReply.cs
- TriggerBase.cs
- PrintController.cs
- CaseKeyBox.ViewModel.cs
- SQLBinary.cs
- KeyValuePairs.cs
- Graph.cs
- dbenumerator.cs
- ToolStripDropDownClosedEventArgs.cs
- ParsedAttributeCollection.cs
- ResourceCategoryAttribute.cs
- WebPartZoneBase.cs
- NullReferenceException.cs
- Zone.cs
- EventItfInfo.cs
- ConfigurationException.cs
- Vector3DCollection.cs
- ColumnMapTranslator.cs
- GenericIdentity.cs