Code:
/ 4.0 / 4.0 / 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. //------------------------------------------------------------------------------ // // 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
- DbSetClause.cs
- updatecommandorderer.cs
- XmlIlGenerator.cs
- DelegateInArgument.cs
- Point3DCollectionConverter.cs
- TemplateKeyConverter.cs
- DuplicateWaitObjectException.cs
- PreloadedPackages.cs
- contentDescriptor.cs
- LinkLabelLinkClickedEvent.cs
- ByteStack.cs
- HttpWebRequest.cs
- PropertyChangeTracker.cs
- messageonlyhwndwrapper.cs
- DataServiceClientException.cs
- SourceItem.cs
- _UriTypeConverter.cs
- StringFunctions.cs
- AttributeUsageAttribute.cs
- FrugalList.cs
- Int64AnimationBase.cs
- BindingOperations.cs
- DataSourceSelectArguments.cs
- DoubleCollectionValueSerializer.cs
- ResourceAssociationTypeEnd.cs
- TextPenaltyModule.cs
- Header.cs
- odbcmetadatacolumnnames.cs
- RelationshipEndCollection.cs
- ExtensibleClassFactory.cs
- TagPrefixInfo.cs
- AppDomainProtocolHandler.cs
- Sql8ExpressionRewriter.cs
- RayHitTestParameters.cs
- CapabilitiesAssignment.cs
- DeclaredTypeElementCollection.cs
- Claim.cs
- PriorityQueue.cs
- TextTreeNode.cs
- Parameter.cs
- MatchingStyle.cs
- XmlReflectionMember.cs
- ReadOnlyDictionary.cs
- CategoryAttribute.cs
- MaterialGroup.cs
- GetMemberBinder.cs
- TextEditorMouse.cs
- FixedBufferAttribute.cs
- HtmlTitle.cs
- LabelLiteral.cs
- DataGridViewComponentPropertyGridSite.cs
- ScrollEventArgs.cs
- FactoryGenerator.cs
- Material.cs
- ToolStripCustomTypeDescriptor.cs
- ScrollableControl.cs
- ConnectionOrientedTransportChannelFactory.cs
- QueryableDataSourceView.cs
- FixedSOMPage.cs
- MulticastNotSupportedException.cs
- Attribute.cs
- CompositeCollectionView.cs
- ZipIOModeEnforcingStream.cs
- SelectionEditor.cs
- ButtonPopupAdapter.cs
- WebConfigurationFileMap.cs
- DurableOperationContext.cs
- DoubleKeyFrameCollection.cs
- TimeSpan.cs
- util.cs
- ScriptControlDescriptor.cs
- ErrorFormatter.cs
- FixedDocumentPaginator.cs
- PlainXmlWriter.cs
- DependencyObjectType.cs
- FixedSchema.cs
- ConfigUtil.cs
- GenericUI.cs
- DirectionalLight.cs
- DelegateArgument.cs
- XmlAnyAttributeAttribute.cs
- ViewGenerator.cs
- MessageBox.cs
- LZCodec.cs
- ConversionContext.cs
- DataControlReferenceCollection.cs
- TagPrefixAttribute.cs
- RequestQueue.cs
- NonParentingControl.cs
- ListViewCancelEventArgs.cs
- Substitution.cs
- cookie.cs
- Missing.cs
- HostingEnvironmentSection.cs
- GPStream.cs
- DataGridViewCellCancelEventArgs.cs
- OLEDB_Util.cs
- TemplateApplicationHelper.cs
- SQLDecimal.cs
- AdornerHitTestResult.cs