Esempio n. 1
0
        public static SchemaInfo ReadAndValidateSchema(XmlReader reader, string baseDirectoryForIncludes, IncludeInfo include)
        {
#if SOODA_NO_VALIDATING_READER
            XmlSerializer ser        = new XmlSerializer(typeof(Sooda.Schema.SchemaInfo));
            SchemaInfo    schemaInfo = (SchemaInfo)ser.Deserialize(reader);
#else
            XmlReaderSettings readerSettings = new XmlReaderSettings();
            readerSettings.ValidationType = ValidationType.Schema;
            readerSettings.Schemas.Add(NamespaceURI, GetSchemaXsdStreamXmlReader());
            XmlReader validatingReader = XmlReader.Create(reader, readerSettings);

            XmlSerializer ser        = new XmlSerializer(typeof(Sooda.Schema.SchemaInfo));
            SchemaInfo    schemaInfo = (SchemaInfo)ser.Deserialize(validatingReader);
#endif

            if (baseDirectoryForIncludes != null)
            {
                ProcessIncludes(schemaInfo, schemaInfo.Includes, baseDirectoryForIncludes);
            }

            if (include == null)
            {
                schemaInfo.Resolve();
            }
            else if (!string.IsNullOrEmpty(include.AssemblyName))
            {
                foreach (ClassInfo ci in schemaInfo.Classes)
                {
                    ci.Schema = schemaInfo;
                }
            }
            return(schemaInfo);
        }
Esempio n. 2
0
        public static SchemaInfo ReadAndValidateSchema(XmlReader reader, string baseDirectoryForIncludes, IncludeInfo include)
        {
#if SOODA_NO_VALIDATING_READER
            XmlSerializer ser = new XmlSerializer(typeof(Sooda.Schema.SchemaInfo));
            SchemaInfo schemaInfo = (SchemaInfo)ser.Deserialize(reader);
#else

            XmlReaderSettings readerSettings = new XmlReaderSettings();
            readerSettings.ValidationType = ValidationType.Schema;
            readerSettings.Schemas.Add(NamespaceURI, GetSchemaXsdStreamXmlReader());
            XmlReader validatingReader = XmlReader.Create(reader, readerSettings);

            XmlSerializer ser = new XmlSerializer(typeof(Sooda.Schema.SchemaInfo));
            SchemaInfo schemaInfo = (SchemaInfo)ser.Deserialize(validatingReader);
#endif

            if (baseDirectoryForIncludes != null)
            {
                ProcessIncludes(schemaInfo, schemaInfo.Includes, baseDirectoryForIncludes);
            }

            if (include == null)
                schemaInfo.Resolve();
            else if (!string.IsNullOrEmpty(include.AssemblyName))
            {
                foreach (ClassInfo ci in schemaInfo.Classes)
                    ci.Schema = schemaInfo;
            }
            return schemaInfo;
        }