Inheritance: IDtdInfo
Example #1
0
        internal void StartParsing(XmlReader reader, string targetNamespace, SchemaInfo schemaInfo) {
            this.reader = reader;
            positionInfo = PositionInfo.GetPositionInfo(reader);
            this.namespaceManager = reader.NamespaceManager;
            if (this.namespaceManager == null) {
                this.namespaceManager = new XmlNamespaceManager(this.nameTable);
                this.isProcessNamespaces = true;
            } 
            else {
                this.isProcessNamespaces = false;
            }
            while (this.reader.NodeType != XmlNodeType.Element && this.reader.Read()) {}

            this.markupDepth = int.MaxValue;
			this.schemaXmlDepth = reader.Depth;
            XmlQualifiedName qname = new XmlQualifiedName(this.reader.LocalName, XmlSchemaDatatype.XdrCanonizeUri(this.reader.NamespaceURI, this.nameTable, this.schemaNames));
            if (this.schemaNames.IsXDRRoot(qname)) {
                Debug.Assert(schemaInfo != null);
                schemaInfo.SchemaType = SchemaType.XDR;
                this.schema = null;
                this.builder = new XdrBuilder(reader, this.namespaceManager, schemaInfo, targetNamespace, this.nameTable, this.schemaNames, this.validationEventHandler);
            }
            else if (this.schemaNames.IsXSDRoot(qname)) {
                if (schemaInfo != null) {
                    schemaInfo.SchemaType = SchemaType.XSD;
                }
                this.schema = new XmlSchema();
                this.schema.BaseUri = reader.BaseURI;
                this.builder = new XsdBuilder(reader, this.namespaceManager, this.schema, this.nameTable, this.schemaNames, this.validationEventHandler);
            }
            else { 
                throw new XmlSchemaException(Res.Sch_SchemaRootExpected, reader.BaseURI, positionInfo.LineNumber, positionInfo.LinePosition);
            }
                
        }
        public async Task StartParsingAsync(XmlReader reader, string targetNamespace) {
            this.reader = reader;
            positionInfo = PositionInfo.GetPositionInfo(reader);
            namespaceManager = reader.NamespaceManager;
            if (namespaceManager == null) {
                namespaceManager = new XmlNamespaceManager(nameTable);
                isProcessNamespaces = true;
            } 
            else {
                isProcessNamespaces = false;
            }
            while (reader.NodeType != XmlNodeType.Element && await reader.ReadAsync().ConfigureAwait(false)) {}

            markupDepth = int.MaxValue;
            schemaXmlDepth = reader.Depth;
            SchemaType rootType = schemaNames.SchemaTypeFromRoot(reader.LocalName, reader.NamespaceURI);
            
            string code;
            if (!CheckSchemaRoot(rootType, out code)) {
                throw new XmlSchemaException(code, reader.BaseURI, positionInfo.LineNumber, positionInfo.LinePosition);
            }
            
            if (schemaType == SchemaType.XSD) {
                schema = new XmlSchema();
                schema.BaseUri = new Uri(reader.BaseURI, UriKind.RelativeOrAbsolute);
                builder = new XsdBuilder(reader, namespaceManager, schema, nameTable, schemaNames, eventHandler);
            }
            else {  
                Debug.Assert(schemaType == SchemaType.XDR);
                xdrSchema = new SchemaInfo();
                xdrSchema.SchemaType = SchemaType.XDR;
                builder = new XdrBuilder(reader, namespaceManager, xdrSchema, targetNamespace, nameTable, schemaNames, eventHandler);
                ((XdrBuilder)builder).XmlResolver = xmlResolver;
            }
        }
Example #3
0
        private void Init()
        {
            _nsManager = reader.NamespaceManager;
            if (_nsManager == null)
            {
                _nsManager = new XmlNamespaceManager(NameTable);
                _bManageNamespaces = true;
            }
            _validationStack = new HWStack(STACK_INCREMENT);
            textValue = new StringBuilder();
            _attPresence = new Hashtable();
            schemaInfo = new SchemaInfo();
            checkDatatype = false;
            _processContents = XmlSchemaContentProcessing.Strict;
            Push(XmlQualifiedName.Empty);

            //Add common strings to be compared to NameTable
            _nsXmlNs = NameTable.Add(XmlReservedNs.NsXmlNs);
            _nsXs = NameTable.Add(XmlReservedNs.NsXs);
            _nsXsi = NameTable.Add(XmlReservedNs.NsXsi);
            _xsiType = NameTable.Add("type");
            _xsiNil = NameTable.Add("nil");
            _xsiSchemaLocation = NameTable.Add("schemaLocation");
            _xsiNoNamespaceSchemaLocation = NameTable.Add("noNamespaceSchemaLocation");
            _xsdSchema = NameTable.Add("schema");
        }
Example #4
0
 internal void Compile(XmlSchema schema, string targetNamespace, SchemaInfo schemaInfo) {
     //CompModSwitches.XmlSchema.Level = TraceLevel.Error;
     schema.ErrorCount = 0;
     Preprocess(schema, targetNamespace);
     if (schema.ErrorCount == 0) {
         CompileTo(schemaInfo);
     }
 }
 private void Init() {
     Debug.Assert(reader != null);
     validationStack = new HWStack(STACK_INCREMENT);
     textValue = new StringBuilder();
     name = XmlQualifiedName.Empty;
     attPresence = new Hashtable();
     schemaInfo = new SchemaInfo();
     checkDatatype = false;
     Push(name);
 }
 public bool Execute(XmlSchema schema, SchemaInfo schemaInfo, bool compileContentModel) {
     this.compileContentModel = compileContentModel;
     this.schema = schema;
     Prepare();
     Cleanup();
     Compile();
     if (!HasErrors) {
         Output(schemaInfo);
     }
     return !HasErrors;
 }
 public bool Execute(XmlSchemaSet schemaSet, SchemaInfo schemaCompiledInfo) {
     Compile();
     if (!HasErrors) {
         Output(schemaCompiledInfo);
         schemaSet.elements = elements;
         schemaSet.attributes = attributes;
         schemaSet.schemaTypes = schemaTypes;
         schemaSet.substitutionGroups = examplars;
     }
     return !HasErrors;
 }
 public static void CheckDefaultValue(string value, SchemaAttDef attdef, SchemaInfo sinfo, XmlNamespaceManager nsManager, XmlNameTable NameTable, object sender, ValidationEventHandler eventhandler, string baseUri, int lineNo, int linePos)
 {
     try
     {
         XmlSchemaDatatype datatype = attdef.Datatype;
         if (datatype != null)
         {
             if (datatype.TokenizedType != XmlTokenizedType.CDATA)
             {
                 value = value.Trim();
             }
             if (value.Length != 0)
             {
                 object pVal = datatype.ParseValue(value, NameTable, nsManager);
                 XmlTokenizedType tokenizedType = datatype.TokenizedType;
                 if (tokenizedType == XmlTokenizedType.ENTITY)
                 {
                     if (datatype.Variety == XmlSchemaDatatypeVariety.List)
                     {
                         string[] strArray = (string[]) pVal;
                         for (int i = 0; i < strArray.Length; i++)
                         {
                             BaseValidator.ProcessEntity(sinfo, strArray[i], sender, eventhandler, baseUri, lineNo, linePos);
                         }
                     }
                     else
                     {
                         BaseValidator.ProcessEntity(sinfo, (string) pVal, sender, eventhandler, baseUri, lineNo, linePos);
                     }
                 }
                 else if ((tokenizedType == XmlTokenizedType.ENUMERATION) && !attdef.CheckEnumeration(pVal))
                 {
                     XmlSchemaException ex = new XmlSchemaException("Sch_EnumerationValue", pVal.ToString(), baseUri, lineNo, linePos);
                     if (eventhandler == null)
                     {
                         throw ex;
                     }
                     eventhandler(sender, new ValidationEventArgs(ex));
                 }
                 attdef.DefaultValueTyped = pVal;
             }
         }
     }
     catch
     {
         XmlSchemaException exception2 = new XmlSchemaException("Sch_AttributeDefaultDataType", attdef.Name.ToString(), baseUri, lineNo, linePos);
         if (eventhandler == null)
         {
             throw exception2;
         }
         eventhandler(sender, new ValidationEventArgs(exception2));
     }
 }
 internal void Add(SchemaInfo sinfo, ValidationEventHandler eventhandler)
 {
     if (this.schemaType == System.Xml.Schema.SchemaType.None)
     {
         this.schemaType = sinfo.SchemaType;
     }
     else if (this.schemaType != sinfo.SchemaType)
     {
         if (eventhandler != null)
         {
             eventhandler(this, new ValidationEventArgs(new XmlSchemaException("Sch_MixSchemaTypes", string.Empty)));
         }
         return;
     }
     foreach (string str in sinfo.TargetNamespaces.Keys)
     {
         if (!this.targetNamespaces.ContainsKey(str))
         {
             this.targetNamespaces.Add(str, true);
         }
     }
     foreach (KeyValuePair<XmlQualifiedName, SchemaElementDecl> pair in sinfo.elementDecls)
     {
         if (!this.elementDecls.ContainsKey(pair.Key))
         {
             this.elementDecls.Add(pair.Key, pair.Value);
         }
     }
     foreach (KeyValuePair<XmlQualifiedName, SchemaElementDecl> pair2 in sinfo.elementDeclsByType)
     {
         if (!this.elementDeclsByType.ContainsKey(pair2.Key))
         {
             this.elementDeclsByType.Add(pair2.Key, pair2.Value);
         }
     }
     foreach (SchemaAttDef def in sinfo.AttributeDecls.Values)
     {
         if (!this.attributeDecls.ContainsKey(def.Name))
         {
             this.attributeDecls.Add(def.Name, def);
         }
     }
     foreach (SchemaNotation notation in sinfo.Notations.Values)
     {
         if (!this.Notations.ContainsKey(notation.Name.Name))
         {
             this.Notations.Add(notation.Name.Name, notation);
         }
     }
 }
 private void Init() {
     nsManager = reader.NamespaceManager;
     if (nsManager == null) {
         nsManager = new XmlNamespaceManager(NameTable);
         isProcessContents = true;
     }
     validationStack = new HWStack(STACK_INCREMENT);
     textValue = new StringBuilder();
     name = XmlQualifiedName.Empty;
     attPresence = new Hashtable();
     Push(XmlQualifiedName.Empty);
     schemaInfo = new SchemaInfo();
     checkDatatype = false;
 }
 internal XdrBuilder(XmlReader reader, XmlNamespaceManager curmgr, SchemaInfo sinfo, string targetNamspace, XmlNameTable nameTable, SchemaNames schemaNames, ValidationEventHandler eventhandler)
 {
     this._SchemaInfo = sinfo;
     this._TargetNamespace = targetNamspace;
     this._reader = reader;
     this._CurNsMgr = curmgr;
     this.validationEventHandler = eventhandler;
     this._StateHistory = new HWStack(10);
     this._ElementDef = new ElementContent();
     this._AttributeDef = new AttributeContent();
     this._GroupStack = new HWStack(10);
     this._GroupDef = new GroupContent();
     this._NameTable = nameTable;
     this._SchemaNames = schemaNames;
     this._CurState = S_SchemaEntries[0];
     this.positionInfo = PositionInfo.GetPositionInfo(this._reader);
     this.xmlResolver = new XmlUrlResolver();
 }
 internal void AddCompiledInfo(SchemaInfo schemaInfo)
 {
     XmlQualifiedName qualifiedName;
     foreach (XmlSchemaElement element in this.elements.Values)
     {
         qualifiedName = element.QualifiedName;
         schemaInfo.TargetNamespaces[qualifiedName.Namespace] = true;
         if (schemaInfo.ElementDecls[qualifiedName] == null)
         {
             schemaInfo.ElementDecls.Add(qualifiedName, element.ElementDecl);
         }
     }
     foreach (XmlSchemaAttribute attribute in this.attributes.Values)
     {
         qualifiedName = attribute.QualifiedName;
         schemaInfo.TargetNamespaces[qualifiedName.Namespace] = true;
         if (schemaInfo.ElementDecls[qualifiedName] == null)
         {
             schemaInfo.AttributeDecls.Add(qualifiedName, attribute.AttDef);
         }
     }
     foreach (XmlSchemaType type in this.types.Values)
     {
         qualifiedName = type.QualifiedName;
         schemaInfo.TargetNamespaces[qualifiedName.Namespace] = true;
         if ((!(type is XmlSchemaComplexType) || (type != XmlSchemaComplexType.AnyType)) && (schemaInfo.ElementDeclsByType[qualifiedName] == null))
         {
             schemaInfo.ElementDeclsByType.Add(qualifiedName, type.ElementDecl);
         }
     }
     foreach (XmlSchemaNotation notation in this.notations.Values)
     {
         qualifiedName = notation.QualifiedName;
         schemaInfo.TargetNamespaces[qualifiedName.Namespace] = true;
         SchemaNotation notation2 = new SchemaNotation(qualifiedName) {
             SystemLiteral = notation.System,
             Pubid = notation.Public
         };
         if (schemaInfo.Notations[qualifiedName.Name] == null)
         {
             schemaInfo.Notations.Add(qualifiedName.Name, notation2);
         }
     }
 }
 public static void CheckDefaultValue(SchemaAttDef attdef, SchemaInfo sinfo, IValidationEventHandling eventHandling, string baseUriStr)
 {
     try
     {
         if (baseUriStr == null)
         {
             baseUriStr = string.Empty;
         }
         XmlSchemaDatatype datatype = attdef.Datatype;
         if (datatype != null)
         {
             object defaultValueTyped = attdef.DefaultValueTyped;
             XmlTokenizedType tokenizedType = datatype.TokenizedType;
             if (tokenizedType == XmlTokenizedType.ENTITY)
             {
                 if (datatype.Variety == XmlSchemaDatatypeVariety.List)
                 {
                     string[] strArray = (string[]) defaultValueTyped;
                     for (int i = 0; i < strArray.Length; i++)
                     {
                         BaseValidator.ProcessEntity(sinfo, strArray[i], eventHandling, baseUriStr, attdef.ValueLineNumber, attdef.ValueLinePosition);
                     }
                 }
                 else
                 {
                     BaseValidator.ProcessEntity(sinfo, (string) defaultValueTyped, eventHandling, baseUriStr, attdef.ValueLineNumber, attdef.ValueLinePosition);
                 }
             }
             else if (((tokenizedType == XmlTokenizedType.ENUMERATION) && !attdef.CheckEnumeration(defaultValueTyped)) && (eventHandling != null))
             {
                 XmlSchemaException exception = new XmlSchemaException("Sch_EnumerationValue", defaultValueTyped.ToString(), baseUriStr, attdef.ValueLineNumber, attdef.ValueLinePosition);
                 eventHandling.SendEvent(exception, XmlSeverityType.Error);
             }
         }
     }
     catch (Exception)
     {
         if (eventHandling != null)
         {
             XmlSchemaException exception2 = new XmlSchemaException("Sch_AttributeDefaultDataType", attdef.Name.ToString());
             eventHandling.SendEvent(exception2, XmlSeverityType.Error);
         }
     }
 }
Example #14
0
        internal Validator(XmlNameTable nameTable, SchemaNames schemaNames, XmlValidatingReader reader) {
            this.nameTable = nameTable;
            this.schemaNames = schemaNames;
            this.reader = reader;
            positionInfo = PositionInfo.GetPositionInfo(reader);
            nsManager = reader.NamespaceManager;
            if (nsManager == null) {
                nsManager = new XmlNamespaceManager(nameTable);
                isProcessContents = true;
            }
            SchemaInfo = new SchemaInfo(schemaNames);

            validationStack = new HWStack(STACK_INCREMENT);
            textValue = new StringBuilder();
            this.name = XmlQualifiedName.Empty;
            attPresence = new Hashtable();
            context = null;
            attnDef = null;
        }
 public XmlSchemaSet(XmlNameTable nameTable)
 {
     if (nameTable == null)
     {
         throw new ArgumentNullException("nameTable");
     }
     this.nameTable = nameTable;
     this.schemas = new SortedList();
     this.schemaLocations = new Hashtable();
     this.chameleonSchemas = new Hashtable();
     this.targetNamespaces = new Hashtable();
     this.internalEventHandler = new System.Xml.Schema.ValidationEventHandler(this.InternalValidationCallback);
     this.eventHandler = this.internalEventHandler;
     this.readerSettings = new XmlReaderSettings();
     this.readerSettings.NameTable = nameTable;
     this.readerSettings.DtdProcessing = DtdProcessing.Prohibit;
     this.compilationSettings = new XmlSchemaCompilationSettings();
     this.cachedCompiledInfo = new SchemaInfo();
     this.compileAll = true;
 }
Example #16
0
        internal void Check(SchemaInfo sinfo, Validator validator, ValidationEventHandler eventhandler) {
            Object o = null;
            string code = null;

            switch (RefType) {
            case ForwardRef.Type.ID:
                o = validator.FindID(ID);
                code = Res.Sch_UndeclaredId;
                break;
            case ForwardRef.Type.NOTATION:
                o = sinfo.Notations[ID];
                code = Res.Sch_UndeclaredNotation;
                break;
            }

            if (o == null) {
                string baseuri = (null != validator && null != validator.BaseUri ? validator.BaseUri.AbsolutePath : string.Empty);
                eventhandler(this, new ValidationEventArgs(new XmlSchemaException(code, ID, baseuri, Line, Col)));
            }
        }
Example #17
0
        protected static void ProcessEntity(SchemaInfo sinfo, string name, IValidationEventHandling eventHandling, string baseUriStr, int lineNumber, int linePosition) {
            SchemaEntity en;
            string errorResId = null;
            if (!sinfo.GeneralEntities.TryGetValue(new XmlQualifiedName(name), out en)) {
                // validation error, see xml spec [68]
                errorResId = Res.Sch_UndeclaredEntity;

            }
            else if (en.NData.IsEmpty) {
                errorResId = Res.Sch_UnparsedEntityRef;
            }
            if (errorResId != null) {
                XmlSchemaException e = new XmlSchemaException(errorResId, name, baseUriStr, lineNumber, linePosition);

                if (eventHandling != null) {
                    eventHandling.SendEvent(e, XmlSeverityType.Error);
                }
                else {
                    throw e;
                }
            }
        }
Example #18
0
 protected static void ProcessEntity(SchemaInfo sinfo, string name, object sender, ValidationEventHandler eventhandler, string baseUri, int lineNumber, int linePosition) {
     SchemaEntity en;
     XmlSchemaException e = null;
     if (!sinfo.GeneralEntities.TryGetValue(new XmlQualifiedName(name), out en)) {
         // validation error, see xml spec [68]
         e = new XmlSchemaException(Res.Sch_UndeclaredEntity, name, baseUri, lineNumber, linePosition);
     }
     else if (en.NData.IsEmpty) {
         e = new XmlSchemaException(Res.Sch_UnparsedEntityRef, name, baseUri, lineNumber, linePosition);
     }
     if (e != null) {
         if (eventhandler != null) {
             eventhandler(sender, new ValidationEventArgs(e));
         }
         else {
             throw e;
         }
     }
 }
Example #19
0
        internal void CopyFromCompiledSet(XmlSchemaSet otherSet)
        {
            SortedList sortedSchemas = otherSet.SortedSchemas;
            bool       flag          = this.schemas.Count == 0;
            ArrayList  list2         = new ArrayList();
            SchemaInfo info          = new SchemaInfo();

            for (int i = 0; i < sortedSchemas.Count; i++)
            {
                XmlSchema byIndex = (XmlSchema)sortedSchemas.GetByIndex(i);
                Uri       baseUri = byIndex.BaseUri;
                if (this.schemas.ContainsKey(byIndex.SchemaId) || (((baseUri != null) && (baseUri.OriginalString.Length != 0)) && (this.schemaLocations[baseUri] != null)))
                {
                    list2.Add(byIndex);
                }
                else
                {
                    this.schemas.Add(byIndex.SchemaId, byIndex);
                    if ((baseUri != null) && (baseUri.OriginalString.Length != 0))
                    {
                        this.schemaLocations.Add(baseUri, byIndex);
                    }
                    string targetNamespace = this.GetTargetNamespace(byIndex);
                    if (this.targetNamespaces[targetNamespace] == null)
                    {
                        this.targetNamespaces.Add(targetNamespace, targetNamespace);
                    }
                }
            }
            this.VerifyTables();
            foreach (XmlSchemaElement element in otherSet.GlobalElements.Values)
            {
                if (!this.AddToTable(this.elements, element.QualifiedName, element))
                {
                    goto Label_026E;
                }
            }
            foreach (XmlSchemaAttribute attribute in otherSet.GlobalAttributes.Values)
            {
                if (!this.AddToTable(this.attributes, attribute.QualifiedName, attribute))
                {
                    goto Label_026E;
                }
            }
            foreach (XmlSchemaType type in otherSet.GlobalTypes.Values)
            {
                if (!this.AddToTable(this.schemaTypes, type.QualifiedName, type))
                {
                    goto Label_026E;
                }
            }
            this.ProcessNewSubstitutionGroups(otherSet.SubstitutionGroups, false);
            info.Add(this.cachedCompiledInfo, this.eventHandler);
            info.Add(otherSet.CompiledInfo, this.eventHandler);
            this.cachedCompiledInfo = info;
            if (flag)
            {
                this.isCompiled = true;
                this.compileAll = false;
            }
            return;

Label_026E:
            foreach (XmlSchema schema2 in sortedSchemas.Values)
            {
                if (!list2.Contains(schema2))
                {
                    this.Remove(schema2, false);
                }
            }
            foreach (XmlSchemaElement element2 in otherSet.GlobalElements.Values)
            {
                if (!list2.Contains((XmlSchema)element2.Parent))
                {
                    this.elements.Remove(element2.QualifiedName);
                }
            }
            foreach (XmlSchemaAttribute attribute2 in otherSet.GlobalAttributes.Values)
            {
                if (!list2.Contains((XmlSchema)attribute2.Parent))
                {
                    this.attributes.Remove(attribute2.QualifiedName);
                }
            }
            foreach (XmlSchemaType type2 in otherSet.GlobalTypes.Values)
            {
                if (!list2.Contains((XmlSchema)type2.Parent))
                {
                    this.schemaTypes.Remove(type2.QualifiedName);
                }
            }
        }
 private void Output(SchemaInfo schemaInfo) {
     string tns;
     foreach(XmlSchema schema in schemasToCompile.Values) {
         tns = schema.TargetNamespace;
         if (tns == null) {
             tns = string.Empty;
         }
         schemaInfo.TargetNamespaces[tns] = true;
     }
     foreach (XmlSchemaElement element in elements.Values) {
         schemaInfo.ElementDecls.Add(element.QualifiedName, element.ElementDecl);
     }
     foreach (XmlSchemaAttribute attribute in attributes.Values) {
         schemaInfo.AttributeDecls.Add(attribute.QualifiedName, attribute.AttDef);
     }    
     foreach (XmlSchemaType type in schemaTypes.Values) {
         schemaInfo.ElementDeclsByType.Add(type.QualifiedName, type.ElementDecl);
     }
     foreach (XmlSchemaNotation notation in notations.Values) {
         SchemaNotation no = new SchemaNotation(notation.QualifiedName);
         no.SystemLiteral = notation.System;
         no.Pubid = notation.Public;
         if (!schemaInfo.Notations.ContainsKey(no.Name.Name)) {
             schemaInfo.Notations.Add(no.Name.Name, no);
         }
     }
    
 }
        private XmlSchema Add(string ns, SchemaInfo schemaInfo, XmlSchema schema, bool compile, XmlResolver resolver) {
            int errorCount = 0;
            if (schema != null) {
                if (schema.ErrorCount == 0 && compile) {
					if (!schema.CompileSchema(this, resolver, schemaInfo, ns, validationEventHandler, nameTable, true)) {
						errorCount = 1;
					}
					ns = schema.TargetNamespace == null ? string.Empty : schema.TargetNamespace;
                }
				errorCount += schema.ErrorCount;
            } 
            else {
                errorCount += schemaInfo.ErrorCount;
                //ns = ns == null? string.Empty : NameTable.Add(ns);
                ns = NameTable.Add(ns); //Added without checking for ns == null, since XDR cannot have null namespace
            }
            if (errorCount == 0) {
                XmlSchemaCollectionNode node = new XmlSchemaCollectionNode();
                node.NamespaceURI = ns;
                node.SchemaInfo = schemaInfo; 
				node.Schema = schema; 
                Add(ns, node);
                return schema;
            }
            return null;
        }
Example #22
0
 private bool LoadSchema(string uri)
 {
     if (_xmlResolver == null)
     {
         return false;
     }
     uri = _NameTable.Add(uri);
     if (_SchemaInfo.TargetNamespaces.ContainsKey(uri))
     {
         return false;
     }
     SchemaInfo schemaInfo = null;
     Uri _baseUri = _xmlResolver.ResolveUri(null, _reader.BaseURI);
     XmlReader reader = null;
     try
     {
         Uri ruri = _xmlResolver.ResolveUri(_baseUri, uri.Substring(x_schema.Length));
         Stream stm = (Stream)_xmlResolver.GetEntity(ruri, null, null);
         reader = new XmlTextReader(ruri.ToString(), stm, _NameTable);
         schemaInfo = new SchemaInfo();
         Parser parser = new Parser(SchemaType.XDR, _NameTable, _SchemaNames, _validationEventHandler);
         parser.XmlResolver = _xmlResolver;
         parser.Parse(reader, uri);
         schemaInfo = parser.XdrSchema;
     }
     catch (XmlException e)
     {
         SendValidationEvent(SR.Sch_CannotLoadSchema, new string[] { uri, e.Message }, XmlSeverityType.Warning);
         schemaInfo = null;
     }
     finally
     {
         if (reader != null)
         {
             reader.Close();
         }
     }
     if (schemaInfo != null && schemaInfo.ErrorCount == 0)
     {
         _SchemaInfo.Add(schemaInfo, _validationEventHandler);
         return true;
     }
     return false;
 }
Example #23
0
 internal XmlSchema?Add(string?ns, SchemaInfo schemaInfo, XmlSchema?schema, bool compile)
 {
     return(Add(ns, schemaInfo, schema, compile, _xmlResolver));
 }
Example #24
0
        public void Compile()
        {
            if (!this.isCompiled)
            {
                if (this.schemas.Count == 0)
                {
                    this.ClearTables();
                    this.cachedCompiledInfo = new SchemaInfo();
                    this.isCompiled         = true;
                    this.compileAll         = false;
                }
                else
                {
                    lock (this.InternalSyncObject)
                    {
                        if (!this.isCompiled)
                        {
                            Compiler   compiler           = new Compiler(this.nameTable, this.eventHandler, this.schemaForSchema, this.compilationSettings);
                            SchemaInfo schemaCompiledInfo = new SchemaInfo();
                            int        index = 0;
                            if (!this.compileAll)
                            {
                                compiler.ImportAllCompiledSchemas(this);
                            }
                            try
                            {
                                XmlSchema buildInSchema = Preprocessor.GetBuildInSchema();
                                index = 0;
                                while (index < this.schemas.Count)
                                {
                                    XmlSchema byIndex = (XmlSchema)this.schemas.GetByIndex(index);
                                    Monitor.Enter(byIndex);
                                    if (!byIndex.IsPreprocessed)
                                    {
                                        this.SendValidationEvent(new XmlSchemaException("Sch_SchemaNotPreprocessed", string.Empty), XmlSeverityType.Error);
                                        this.isCompiled = false;
                                        goto Label_01BA;
                                    }
                                    if (byIndex.IsCompiledBySet)
                                    {
                                        if (!this.compileAll)
                                        {
                                            goto Label_00FD;
                                        }
                                        if (byIndex == buildInSchema)
                                        {
                                            compiler.Prepare(byIndex, false);
                                            goto Label_00FD;
                                        }
                                    }
                                    compiler.Prepare(byIndex, true);
Label_00FD:
                                    index++;
                                }
                                this.isCompiled = compiler.Execute(this, schemaCompiledInfo);
                                if (this.isCompiled)
                                {
                                    if (!this.compileAll)
                                    {
                                        schemaCompiledInfo.Add(this.cachedCompiledInfo, this.eventHandler);
                                    }
                                    this.compileAll         = false;
                                    this.cachedCompiledInfo = schemaCompiledInfo;
                                }
                            }
                            finally
                            {
                                if (index == this.schemas.Count)
                                {
                                    index--;
                                }
                                for (int i = index; i >= 0; i--)
                                {
                                    XmlSchema schema3 = (XmlSchema)this.schemas.GetByIndex(i);
                                    if (schema3 == Preprocessor.GetBuildInSchema())
                                    {
                                        Monitor.Exit(schema3);
                                    }
                                    else
                                    {
                                        schema3.IsCompiledBySet = this.isCompiled;
                                        Monitor.Exit(schema3);
                                    }
                                }
                            }
                        }
                        Label_01BA :;
                    }
                }
            }
        }
Example #25
0
        public static void CheckDefaultValue(
            SchemaAttDef attdef,
            SchemaInfo sinfo,
            IValidationEventHandling eventHandling,
            string baseUriStr
            )
        {
            try {
                if (baseUriStr == null)
                {
                    baseUriStr = string.Empty;
                }
                XmlSchemaDatatype dtype = attdef.Datatype;
                if (dtype == null)
                {
                    return; // no reason to check
                }
                object typedValue = attdef.DefaultValueTyped;

                // Check special types
                XmlTokenizedType ttype = dtype.TokenizedType;
                if (ttype == XmlTokenizedType.ENTITY)
                {
                    if (dtype.Variety == XmlSchemaDatatypeVariety.List)
                    {
                        string[] ss = (string[])typedValue;
                        for (int i = 0; i < ss.Length; ++i)
                        {
                            ProcessEntity(sinfo, ss[i], eventHandling, baseUriStr, attdef.ValueLineNumber, attdef.ValueLinePosition);
                        }
                    }
                    else
                    {
                        ProcessEntity(sinfo, (string)typedValue, eventHandling, baseUriStr, attdef.ValueLineNumber, attdef.ValueLinePosition);
                    }
                }
                else if (ttype == XmlTokenizedType.ENUMERATION)
                {
                    if (!attdef.CheckEnumeration(typedValue))
                    {
                        if (eventHandling != null)
                        {
                            XmlSchemaException e = new XmlSchemaException(Res.Sch_EnumerationValue, typedValue.ToString(), baseUriStr, attdef.ValueLineNumber, attdef.ValueLinePosition);
                            eventHandling.SendEvent(e, XmlSeverityType.Error);
                        }
                    }
                }
            }
#if DEBUG
            catch (XmlSchemaException ex) {
                Debug.WriteLineIf(DiagnosticsSwitches.XmlSchema.TraceError, ex.Message);
#else
            catch (Exception)  {
#endif

                if (eventHandling != null)
                {
                    XmlSchemaException e = new XmlSchemaException(Res.Sch_AttributeDefaultDataType, attdef.Name.ToString());
                    eventHandling.SendEvent(e, XmlSeverityType.Error);
                }
            }
        }
Example #26
0
        private ValidationType DetectValidationType()
        {
            //Type not yet detected : Check in Schema Collection
            if (reader.Schemas != null && reader.Schemas.Count > 0)
            {
                XmlSchemaCollectionEnumerator enumerator = reader.Schemas.GetEnumerator();
                while (enumerator.MoveNext())
                {
                    XmlSchemaCollectionNode node = enumerator.CurrentNode !;
                    SchemaInfo schemaInfo        = node.SchemaInfo !;
                    if (schemaInfo.SchemaType == SchemaType.XSD)
                    {
                        return(ValidationType.Schema);
                    }
                    else if (schemaInfo.SchemaType == SchemaType.XDR)
                    {
                        return(ValidationType.XDR);
                    }
                }
            }

            if (reader.NodeType == XmlNodeType.Element)
            {
                SchemaType schemaType = SchemaNames.SchemaTypeFromRoot(reader.LocalName, reader.NamespaceURI);
                if (schemaType == SchemaType.XSD)
                {
                    return(ValidationType.Schema);
                }
                else if (schemaType == SchemaType.XDR)
                {
                    return(ValidationType.XDR);
                }
                else
                {
                    int count = reader.AttributeCount;
                    for (int i = 0; i < count; i++)
                    {
                        reader.MoveToAttribute(i);
                        string objectNs   = reader.NamespaceURI;
                        string objectName = reader.LocalName;
                        if (Ref.Equal(objectNs, SchemaNames.NsXmlNs))
                        {
                            if (XdrBuilder.IsXdrSchema(reader.Value))
                            {
                                reader.MoveToElement();
                                return(ValidationType.XDR);
                            }
                        }
                        else if (Ref.Equal(objectNs, SchemaNames.NsXsi))
                        {
                            reader.MoveToElement();
                            return(ValidationType.Schema);
                        }
                        else if (Ref.Equal(objectNs, SchemaNames.QnDtDt.Namespace) && Ref.Equal(objectName, SchemaNames.QnDtDt.Name))
                        {
                            reader.SchemaTypeObject = XmlSchemaDatatype.FromXdrName(reader.Value);
                            reader.MoveToElement();
                            return(ValidationType.XDR);
                        }
                    } //end of for
                    if (count > 0)
                    {
                        reader.MoveToElement();
                    }
                }
            }
            return(ValidationType.Auto);
        }
 private void Output(SchemaInfo schemaInfo)
 {
     foreach (XmlSchemaElement element in this.schema.Elements.Values)
     {
         schemaInfo.TargetNamespaces[element.QualifiedName.Namespace] = true;
         schemaInfo.ElementDecls.Add(element.QualifiedName, element.ElementDecl);
     }
     foreach (XmlSchemaAttribute attribute in this.schema.Attributes.Values)
     {
         schemaInfo.TargetNamespaces[attribute.QualifiedName.Namespace] = true;
         schemaInfo.AttributeDecls.Add(attribute.QualifiedName, attribute.AttDef);
     }
     foreach (XmlSchemaType type in this.schema.SchemaTypes.Values)
     {
         schemaInfo.TargetNamespaces[type.QualifiedName.Namespace] = true;
         XmlSchemaComplexType type2 = type as XmlSchemaComplexType;
         if ((type2 == null) || (!type2.IsAbstract && (type != XmlSchemaComplexType.AnyType)))
         {
             schemaInfo.ElementDeclsByType.Add(type.QualifiedName, type.ElementDecl);
         }
     }
     foreach (XmlSchemaNotation notation in this.schema.Notations.Values)
     {
         schemaInfo.TargetNamespaces[notation.QualifiedName.Namespace] = true;
         SchemaNotation notation2 = new SchemaNotation(notation.QualifiedName) {
             SystemLiteral = notation.System,
             Pubid = notation.Public
         };
         if (!schemaInfo.Notations.ContainsKey(notation2.Name.Name))
         {
             schemaInfo.Notations.Add(notation2.Name.Name, notation2);
         }
     }
 }
 public AutoValidator(XmlValidatingReaderImpl reader, XmlSchemaCollection schemaCollection, ValidationEventHandler eventHandler) : base(reader, schemaCollection, eventHandler) {
     schemaInfo = new SchemaInfo();
 } 
 internal void RecompileSchemaSet()
 {
     if (!this.schemaSet.IsCompiled)
     {
         try
         {
             this.schemaSet.Compile();
         }
         catch (XmlSchemaException exception)
         {
             this.SendValidationEvent(exception);
         }
     }
     this.compiledSchemaInfo = this.schemaSet.CompiledInfo;
 }
Example #30
0
 internal XmlSchema Add(string ns, SchemaInfo schemaInfo, XmlSchema schema, bool compile)
 {
     return(this.Add(ns, schemaInfo, schema, compile, this.xmlResolver));
 }
        private ValidationType DetectValidationType()
        {
            if ((base.reader.Schemas != null) && (base.reader.Schemas.Count > 0))
            {
                XmlSchemaCollectionEnumerator enumerator = base.reader.Schemas.GetEnumerator();
                while (enumerator.MoveNext())
                {
                    SchemaInfo schemaInfo = enumerator.CurrentNode.SchemaInfo;
                    if (schemaInfo.SchemaType == SchemaType.XSD)
                    {
                        return(ValidationType.Schema);
                    }
                    if (schemaInfo.SchemaType == SchemaType.XDR)
                    {
                        return(ValidationType.XDR);
                    }
                }
            }
            if (base.reader.NodeType == XmlNodeType.Element)
            {
                switch (base.SchemaNames.SchemaTypeFromRoot(base.reader.LocalName, base.reader.NamespaceURI))
                {
                case SchemaType.XSD:
                    return(ValidationType.Schema);

                case SchemaType.XDR:
                    return(ValidationType.XDR);
                }
                int attributeCount = base.reader.AttributeCount;
                for (int i = 0; i < attributeCount; i++)
                {
                    base.reader.MoveToAttribute(i);
                    string namespaceURI = base.reader.NamespaceURI;
                    string localName    = base.reader.LocalName;
                    if (Ref.Equal(namespaceURI, base.SchemaNames.NsXmlNs))
                    {
                        if (XdrBuilder.IsXdrSchema(base.reader.Value))
                        {
                            base.reader.MoveToElement();
                            return(ValidationType.XDR);
                        }
                    }
                    else
                    {
                        if (Ref.Equal(namespaceURI, base.SchemaNames.NsXsi))
                        {
                            base.reader.MoveToElement();
                            return(ValidationType.Schema);
                        }
                        if (Ref.Equal(namespaceURI, base.SchemaNames.QnDtDt.Namespace) && Ref.Equal(localName, base.SchemaNames.QnDtDt.Name))
                        {
                            base.reader.SchemaTypeObject = XmlSchemaDatatype.FromXdrName(base.reader.Value);
                            base.reader.MoveToElement();
                            return(ValidationType.XDR);
                        }
                    }
                }
                if (attributeCount > 0)
                {
                    base.reader.MoveToElement();
                }
            }
            return(ValidationType.Auto);
        }
Example #32
0
        public void StartParsing(XmlReader reader, string targetNamespace)
        {
            _reader = reader;
            _positionInfo = PositionInfo.GetPositionInfo(reader);
            _namespaceManager = reader.NamespaceManager;
            if (_namespaceManager == null)
            {
                _namespaceManager = new XmlNamespaceManager(_nameTable);
                _isProcessNamespaces = true;
            }
            else
            {
                _isProcessNamespaces = false;
            }
            while (reader.NodeType != XmlNodeType.Element && reader.Read()) { }

            _markupDepth = int.MaxValue;
            _schemaXmlDepth = reader.Depth;
            SchemaType rootType = _schemaNames.SchemaTypeFromRoot(reader.LocalName, reader.NamespaceURI);

            string code;
            if (!CheckSchemaRoot(rootType, out code))
            {
                throw new XmlSchemaException(code, reader.BaseURI, _positionInfo.LineNumber, _positionInfo.LinePosition);
            }

            if (_schemaType == SchemaType.XSD)
            {
                _schema = new XmlSchema();
                _schema.BaseUri = new Uri(reader.BaseURI, UriKind.RelativeOrAbsolute);
                _builder = new XsdBuilder(reader, _namespaceManager, _schema, _nameTable, _schemaNames, _eventHandler);
            }
            else
            {
                Debug.Assert(_schemaType == SchemaType.XDR);
                _xdrSchema = new SchemaInfo();
                _xdrSchema.SchemaType = SchemaType.XDR;
                _builder = new XdrBuilder(reader, _namespaceManager, _xdrSchema, targetNamespace, _nameTable, _schemaNames, _eventHandler);
                ((XdrBuilder)_builder).XmlResolver = _xmlResolver;
            }
        }
Example #33
0
 public AutoValidator(XmlValidatingReaderImpl reader, XmlSchemaCollection schemaCollection, IValidationEventHandling eventHandling) : base(reader, schemaCollection, eventHandling)
 {
     schemaInfo = new SchemaInfo();
 }
Example #34
0
        //
        // Initialization methods
        //

        private void Initialize(IDtdParserAdapter readerAdapter)
        {
            Debug.Assert(readerAdapter != null);
            _readerAdapter = readerAdapter;
#if !SILVERLIGHT
            _readerAdapterWithValidation = readerAdapter as IDtdParserAdapterWithValidation;
#endif

            _nameTable = readerAdapter.NameTable;

#if !SILVERLIGHT
            IDtdParserAdapterWithValidation raWithValidation = readerAdapter as IDtdParserAdapterWithValidation;
            if (raWithValidation != null)
            {
                _validate = raWithValidation.DtdValidation;
            }
            IDtdParserAdapterV1 raV1 = readerAdapter as IDtdParserAdapterV1;
            if (raV1 != null)
            {
                _v1Compat = raV1.V1CompatibilityMode;
                _normalize = raV1.Normalization;
                _supportNamespaces = raV1.Namespaces;
            }
#endif

            _schemaInfo = new SchemaInfo();
#if !SILVERLIGHT
            _schemaInfo.SchemaType = SchemaType.DTD;
#endif

            _stringBuilder = new StringBuilder();

            Uri baseUri = readerAdapter.BaseUri;
            if (baseUri != null)
            {
                _documentBaseUri = baseUri.ToString();
            }

            _freeFloatingDtd = false;
        }
Example #35
0
        public static void CheckDefaultValue(
            string value,
            SchemaAttDef attdef,
            SchemaInfo sinfo,
            XmlNamespaceManager nsManager,
            XmlNameTable NameTable,
            object sender,
            ValidationEventHandler eventhandler,
            string baseUri,
            int lineNo,
            int linePos
            )
        {
            try
            {
                XmlSchemaDatatype dtype = attdef.Datatype;
                if (dtype == null)
                {
                    return; // no reason to check
                }

                if (dtype.TokenizedType != XmlTokenizedType.CDATA)
                {
                    value = value.Trim();
                }
                if (value.Length == 0)
                {
                    return; // don't need to check
                }
                object typedValue = dtype.ParseValue(value, NameTable, nsManager);

                // Check special types
                XmlTokenizedType ttype = dtype.TokenizedType;
                if (ttype == XmlTokenizedType.ENTITY)
                {
                    if (dtype.Variety == XmlSchemaDatatypeVariety.List)
                    {
                        string[] ss = (string[])typedValue;
                        for (int i = 0; i < ss.Length; ++i)
                        {
                            ProcessEntity(sinfo, ss[i], sender, eventhandler, baseUri, lineNo, linePos);
                        }
                    }
                    else
                    {
                        ProcessEntity(sinfo, (string)typedValue, sender, eventhandler, baseUri, lineNo, linePos);
                    }
                }
                else if (ttype == XmlTokenizedType.ENUMERATION)
                {
                    if (!attdef.CheckEnumeration(typedValue))
                    {
                        XmlSchemaException e = new XmlSchemaException(SR.Sch_EnumerationValue, typedValue.ToString(), baseUri, lineNo, linePos);
                        if (eventhandler != null)
                        {
                            eventhandler(sender, new ValidationEventArgs(e));
                        }
                        else
                        {
                            throw e;
                        }
                    }
                }
                attdef.DefaultValueTyped = typedValue;
            }
#if DEBUG
            catch (XmlSchemaException ex)
            {
                Debug.WriteLineIf(DiagnosticsSwitches.XmlSchema.TraceError, ex.Message);
#else
            catch
            {
#endif
                XmlSchemaException e = new XmlSchemaException(SR.Sch_AttributeDefaultDataType, attdef.Name.ToString(), baseUri, lineNo, linePos);
                if (eventhandler != null)
                {
                    eventhandler(sender, new ValidationEventArgs(e));
                }
                else
                {
                    throw e;
                }
            }
        }
Example #36
0
        /// <summary>
        /// Gets the list schema.
        /// </summary>
        /// <param name="t">The t.</param>
        /// <returns>schema info</returns>
        public static SchemaInfo GetListSchema(this Type t)
        {
            var schemaInfo = new SchemaInfo();
            var classType = new XmlSchemaComplexType
            {
                Name = "ArrayOf" + t.Name
            };

            var sequence = new XmlSchemaSequence();

            schemaInfo.Schema.Items.Add(classType);
            classType.Particle = sequence;
            sequence.Items.Add(new XmlSchemaElement
                                   {
                                       Name = t.Name,
                                       MinOccurs = 0,
                                       MaxOccursString = "unbounded",
                                       SchemaTypeName = new XmlQualifiedName(t.Name)
                                   });


            return schemaInfo;
        }
Example #37
0
        internal void Compile(XmlSchemaCollection collection, XmlNameTable nameTable, SchemaNames schemaNames, ValidationEventHandler validationEventHandler, string targetNamespace, SchemaInfo schemaInfo, bool compileContentModel)
        {
            errorCount = 0;
            if (needCleanup)
            {
                schemaLocations.Clear();
                Compiler.Cleanup(this);
            }
            needCleanup    = true;
            isPreprocessed = false;
            isCompiled     = false;
            if (baseUri != null)
            {
                schemaLocations.Add(baseUri, baseUri);
            }
            LoadExternals(collection, nameTable, schemaNames, validationEventHandler, this);
            if (errorCount == 0)
            {
                new Compiler(nameTable, schemaNames, validationEventHandler, compileContentModel).Compile(this, targetNamespace, schemaInfo);
                if (errorCount == 0)
                {
                    isPreprocessed = true;
                    isCompiled     = true;

                    foreach (XmlSchemaExternal include in Includes)
                    {
                        if (include.Schema != null)
                        {
                            include.Schema.isPreprocessed = true;
                            include.Schema.isCompiled     = true;
                            include.Schema.LineNumber     = include.LineNumber;
                            include.Schema.LinePosition   = include.LinePosition;
                            include.Schema.SourceUri      = include.SchemaLocation;
                        }
                    }
                }
            }
        }
Example #38
0
        /// <summary>
        /// Gets the enum schema.
        /// </summary>
        /// <param name="t">The t.</param>
        /// <returns>schema info</returns>
        public static SchemaInfo GetEnumSchema(this Type t)
        {
            if (!t.IsEnum)
            {
                return null;
            }

            var schemaInfo = new SchemaInfo();
            var classType = new XmlSchemaSimpleType
                                {
                                    Name = t.Name
                                };

            var attribData = t.GetCustomAttributeDataOfType(typeof(DataContractAttribute));
            if (attribData.NamedArguments != null && attribData.NamedArguments.Count > 0)
            {
                foreach (var p1 in attribData.NamedArguments)
                {
                    switch (p1.MemberInfo.Name)
                    {
                        case "Namespace":
                            schemaInfo.Schema.TargetNamespace = p1.TypedValue.Value as string;
                            break;
                    }
                }
            }

            var content = new XmlSchemaSimpleTypeRestriction();
            classType.Content = content;

            content.BaseTypeName = typeof(string).XmlName();
            foreach (var e in t.GetEnumNames())
            {
                content.Facets.Add(new XmlSchemaEnumerationFacet
                                       {
                                           Value = e
                                       });
            }

            schemaInfo.Schema.Items.Add(classType);
            return schemaInfo;
        }
Example #39
0
        /// <summary>
        /// Gets the class schema.
        /// </summary>
        /// <param name="t">The t.</param>
        /// <returns>schema info</returns>
        public static SchemaInfo GetClassSchema(this Type t)
        {
            var schemaInfo = new SchemaInfo();
            var classType = new XmlSchemaComplexType
                                {
                                    Name = t.Name
                                };

            var attribData = t.GetCustomAttributeDataOfType(typeof(DataContractAttribute));
            if (attribData.NamedArguments != null && attribData.NamedArguments.Count > 0)
            {
                foreach (var p1 in attribData.NamedArguments)
                {
                    switch (p1.MemberInfo.Name)
                    {
                        case "Namespace":
                            schemaInfo.Schema.TargetNamespace = p1.TypedValue.Value as string;
                            break;
                    }
                }
            }

            var sequence = new XmlSchemaSequence();

            classType.Particle = sequence;

            var propList = t.GetProperties();

            foreach (var p1 in propList)
            {
                var el = new XmlSchemaElement
                             {
                                 Name = p1.Name,
                                 MinOccurs = 0
                             };

                var xmlName = p1.PropertyType.XmlName();
                if (xmlName != null)
                {
                    el.SchemaTypeName = xmlName;
                }
                else
                {
                    if (p1.PropertyType.IsListType())
                    {
                        // what is this a list of?
                        if (p1.PropertyType.FullName != null)
                        {
                            var pr = Primitive2Xml.XmlName(InternalType(p1.PropertyType.FullName, false));
                            if (pr != null)
                            {
                                el.SchemaTypeName = new XmlQualifiedName("ArrayOf" + pr.Name);
                                schemaInfo.CustomTypes.Add(el.SchemaTypeName);
                            }
                            else
                            {
                                var schName = InternalType(p1.PropertyType.FullName, true);
                                el.SchemaTypeName = new XmlQualifiedName("ArrayOf" + schName);
                                schemaInfo.CustomTypes.Add(new XmlQualifiedName(schName));
                                schemaInfo.CustomTypes.Add(el.SchemaTypeName);
                            }
                        }
                    }
                    else if (p1.PropertyType.Name.Contains("Nullable"))
                    {
                        // what is this a nullable of?
                        if (p1.PropertyType.FullName != null)
                        {
                            var pr = Primitive2Xml.XmlName(InternalType(p1.PropertyType.FullName, false));
                            if (pr != null)
                            {
                                el.SchemaTypeName = pr;
                            }
                            else
                            {
                                var schName = InternalType(p1.PropertyType.FullName, true);
                                el.SchemaTypeName = new XmlQualifiedName(schName);
                                schemaInfo.CustomTypes.Add(el.SchemaTypeName);
                            }

                            el.IsNillable = true;
                        }
                    }
                    else
                    {
                        el.SchemaTypeName = new XmlQualifiedName(p1.PropertyType.Name);
                        schemaInfo.CustomTypes.Add(el.SchemaTypeName);
                    }
                }

                // get data member
                var attrData = p1.GetCustomAttributeDataOfType(typeof(DataMemberAttribute));
                if (attrData != null && attrData.NamedArguments != null
                    && attrData.NamedArguments.Count > 0)
                {
                    foreach (var pp in attrData.NamedArguments)
                    {
                        switch (pp.MemberInfo.Name)
                        {
                            case "IsRequired":
                                {
                                    var v = (bool)pp.TypedValue.Value;
                                    el.MinOccurs = v ? 1 : 0;
                                }

                                break;
                        }
                    }
                }

                sequence.Items.Add(el);
            }


            schemaInfo.Schema.Items.Add(classType);
            return schemaInfo;
        }
Example #40
-1
 internal XdrBuilder(
                    XmlReader reader,
                    XmlNamespaceManager curmgr,
                    SchemaInfo sinfo,
                    string targetNamspace,
                    XmlNameTable nameTable,
                    SchemaNames schemaNames,
                    ValidationEventHandler eventhandler
                    )
 {
     _SchemaInfo = sinfo;
     _TargetNamespace = targetNamspace;
     _reader = reader;
     _CurNsMgr = curmgr;
     _validationEventHandler = eventhandler;
     _StateHistory = new HWStack(StackIncrement);
     _ElementDef = new ElementContent();
     _AttributeDef = new AttributeContent();
     _GroupStack = new HWStack(StackIncrement);
     _GroupDef = new GroupContent();
     _NameTable = nameTable;
     _SchemaNames = schemaNames;
     _CurState = s_schemaEntries[0];
     _positionInfo = PositionInfo.GetPositionInfo(_reader);
     _xmlResolver = null;
 }