System.Xml.Schema.XmlSchemaCollection.Add C# (CSharp) Method

Add() public method

public Add ( String ns, XmlReader reader, XmlResolver resolver ) : XmlSchema
ns String
reader System.Xml.XmlReader
resolver System.Xml.XmlResolver
return XmlSchema
        public XmlSchema Add(String ns, XmlReader reader, XmlResolver resolver)
        {
            if (reader == null)
                throw new ArgumentNullException(nameof(reader));
            XmlNameTable readerNameTable = reader.NameTable;
            SchemaInfo schemaInfo = new SchemaInfo();

            Parser parser = new Parser(SchemaType.None, readerNameTable, GetSchemaNames(readerNameTable), _validationEventHandler);
            parser.XmlResolver = resolver;
            SchemaType schemaType;
            try
            {
                schemaType = parser.Parse(reader, ns);
            }
            catch (XmlSchemaException e)
            {
                SendValidationEvent(e);
                return null;
            }

            if (schemaType == SchemaType.XSD)
            {
                schemaInfo.SchemaType = SchemaType.XSD;
                return Add(ns, schemaInfo, parser.XmlSchema, true, resolver);
            }
            else
            {
                SchemaInfo xdrSchema = parser.XdrSchema;
                return Add(ns, parser.XdrSchema, null, true, resolver);
            }
        }

Same methods

XmlSchemaCollection::Add ( String ns, XmlReader reader ) : XmlSchema
XmlSchemaCollection::Add ( XmlSchema schema ) : XmlSchema
XmlSchemaCollection::Add ( XmlSchema schema, XmlResolver resolver ) : XmlSchema
XmlSchemaCollection::Add ( string ns, SchemaInfo schemaInfo, XmlSchema schema, bool compile ) : XmlSchema
XmlSchemaCollection::Add ( string ns, SchemaInfo schemaInfo, XmlSchema schema, bool compile, XmlResolver resolver ) : XmlSchema
XmlSchemaCollection::Add ( string ns, string uri ) : XmlSchema
XmlSchemaCollection::Add ( XmlSchemaCollection schema ) : void
XmlSchemaCollection::Add ( string ns, XmlSchemaCollectionNode node ) : void

Usage Example

		public void TestAdd ()
		{
			XmlSchemaCollection col = new XmlSchemaCollection ();
			XmlSchema schema = new XmlSchema ();
			XmlSchemaElement elem = new XmlSchemaElement ();
			elem.Name = "foo";
			schema.Items.Add (elem);
			schema.TargetNamespace = "urn:foo";
			col.Add (schema);
			col.Add (schema);	// No problem !?

			XmlSchema schema2 = new XmlSchema ();
			schema2.Items.Add (elem);
			schema2.TargetNamespace = "urn:foo";
			col.Add (schema2);	// No problem !!

			schema.Compile (null);
			col.Add (schema);
			col.Add (schema);	// Still no problem !!!

			schema2.Compile (null);
			col.Add (schema2);

			schema = GetSchema ("Test/XmlFiles/xsd/3.xsd");
			schema.Compile (null);
			col.Add (schema);

			schema2 = GetSchema ("Test/XmlFiles/xsd/3.xsd");
			schema2.Compile (null);
			col.Add (schema2);
		}
All Usage Examples Of System.Xml.Schema.XmlSchemaCollection::Add