Beispiel #1
0
        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);
        }
Beispiel #2
0
 /// <include file='doc\XmlSchemaCollection.uex' path='docs/doc[@for="XmlSchemaCollection.this"]/*' />
 /// <devdoc>
 ///    <para>Looks up the schema by it's associated namespace URI</para>
 /// </devdoc>
 public XmlSchema this[string ns]
 {
     get
     {
         XmlSchemaCollectionNode node = (XmlSchemaCollectionNode)_collection[(ns != null) ? ns : string.Empty];
         return((node != null) ? node.Schema : null);
     }
 }
Beispiel #3
0
        /// <include file='doc\XmlSchemaCollection.uex' path='docs/doc[@for="XmlSchemaCollection.Add3"]/*' />
        /// <devdoc>
        ///    <para>Adds all the namespaces defined in the given collection
        ///       (including their associated schemas) to this collection.</para>
        /// </devdoc>
        public void Add(XmlSchemaCollection schema)
        {
            if (schema == null)
            {
                throw new ArgumentNullException("schema");
            }
            if (this == schema)
            {
                return;
            }
            IDictionaryEnumerator enumerator = schema._collection.GetEnumerator();

            while (enumerator.MoveNext())
            {
                XmlSchemaCollectionNode node = (XmlSchemaCollectionNode)enumerator.Value;
                Add(node.NamespaceURI, node);
            }
        }
Beispiel #4
0
 private void Add(string ns, XmlSchemaCollectionNode node)
 {
     if (_isThreadSafe)
     {
         _wLock.TryEnterWriteLock(_timeout);
     }
     //wLock.AcquireWriterLock(timeout);
     try
     {
         if (_collection[ns] != null)
         {
             _collection.Remove(ns);
         }
         _collection.Add(ns, node);
     }
     finally
     {
         if (_isThreadSafe)
         {
             _wLock.ExitWriteLock();
         }
         //wLock.ReleaseWriterLock();
     }
 }
Beispiel #5
0
        internal SchemaInfo GetSchemaInfo(string ns)
        {
            XmlSchemaCollectionNode node = (XmlSchemaCollectionNode)_collection[(ns != null) ? ns : string.Empty];

            return((node != null) ? node.SchemaInfo : null);
        }
Beispiel #6
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);
        }