Example #1
0
        public static void SetDefaultTypedValue(
            SchemaAttDef attdef,
            IDtdParserAdapter readerAdapter
            )
        {
            try {
                string            value = attdef.DefaultValueExpanded;
                XmlSchemaDatatype dtype = attdef.Datatype;
                if (dtype == null)
                {
                    return; // no reason to check
                }
                if (dtype.TokenizedType != XmlTokenizedType.CDATA)
                {
                    value = value.Trim();
                }
                attdef.DefaultValueTyped = dtype.ParseValue(value, readerAdapter.NameTable, readerAdapter.NamespaceResolver);
            }
#if DEBUG
            catch (XmlSchemaException ex) {
                Debug.WriteLineIf(DiagnosticsSwitches.XmlSchema.TraceError, ex.Message);
#else
            catch (Exception)  {
#endif
                IValidationEventHandling eventHandling = ((IDtdParserAdapterWithValidation)readerAdapter).ValidationEventHandling;
                if (eventHandling != null)
                {
                    XmlSchemaException e = new XmlSchemaException(Res.Sch_AttributeDefaultDataType, attdef.Name.ToString());
                    eventHandling.SendEvent(e, XmlSeverityType.Error);
                }
            }
        }
 public static void SetDefaultTypedValue(SchemaAttDef attdef, IDtdParserAdapter readerAdapter)
 {
     try
     {
         string            defaultValueExpanded = attdef.DefaultValueExpanded;
         XmlSchemaDatatype datatype             = attdef.Datatype;
         if (datatype != null)
         {
             if (datatype.TokenizedType != XmlTokenizedType.CDATA)
             {
                 defaultValueExpanded = defaultValueExpanded.Trim();
             }
             attdef.DefaultValueTyped = datatype.ParseValue(defaultValueExpanded, readerAdapter.NameTable, readerAdapter.NamespaceResolver);
         }
     }
     catch (Exception)
     {
         IValidationEventHandling validationEventHandling = ((IDtdParserAdapterWithValidation)readerAdapter).ValidationEventHandling;
         if (validationEventHandling != null)
         {
             XmlSchemaException exception = new XmlSchemaException("Sch_AttributeDefaultDataType", attdef.Name.ToString());
             validationEventHandling.SendEvent(exception, XmlSeverityType.Error);
         }
     }
 }
        public static void CheckDefaultValue(
            SchemaAttDef attdef,
            SchemaInfo sinfo,
            IDtdParserAdapter readerAdapter
            )
        {
            try {
                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)
                {
                    Uri    baseUri    = readerAdapter.BaseUri;
                    string baseUriStr = (baseUri == null) ? string.Empty : baseUri.ToString();
                    if (dtype.Variety == XmlSchemaDatatypeVariety.List)
                    {
                        string[] ss = (string[])typedValue;
                        foreach (string s in ss)
                        {
                            ProcessEntity(sinfo, s, readerAdapter, readerAdapter.EventHandler, baseUriStr, attdef.ValueLineNum, attdef.ValueLinePos);
                        }
                    }
                    else
                    {
                        ProcessEntity(sinfo, (string)typedValue, readerAdapter, readerAdapter.EventHandler, baseUriStr, attdef.ValueLineNum, attdef.ValueLinePos);
                    }
                }
                else if (ttype == XmlTokenizedType.ENUMERATION)
                {
                    if (!attdef.CheckEnumeration(typedValue))
                    {
                        XmlSchemaException e = new XmlSchemaException(Res.Sch_EnumerationValue, typedValue.ToString(), readerAdapter.BaseUri.ToString(), attdef.ValueLineNum, attdef.ValueLinePos);
                        readerAdapter.SendValidationEvent(XmlSeverityType.Error, e);
                    }
                }
            }
#if DEBUG
            catch (XmlSchemaException ex) {
                Debug.WriteLineIf(DiagnosticsSwitches.XmlSchema.TraceError, ex.Message);
#else
            catch (Exception)  {
#endif
                XmlSchemaException e = new XmlSchemaException(Res.Sch_AttributeDefaultDataType, attdef.Name.ToString());
                readerAdapter.SendValidationEvent(XmlSeverityType.Error, e);
            }
        }
Example #4
0
        private void InitializeFreeFloatingDtd(string baseUri, string docTypeName, string publicId, string systemId, string internalSubset, IDtdParserAdapter adapter)
        {
            Initialize(adapter);

            if (docTypeName == null || docTypeName.Length == 0)
            {
                throw XmlConvert.CreateInvalidNameArgumentException(docTypeName, nameof(docTypeName));
            }

            // check doctype name
            XmlConvert.VerifyName(docTypeName);
            int colonPos = docTypeName.IndexOf(':');
            if (colonPos == -1)
            {
                _schemaInfo.DocTypeName = new XmlQualifiedName(_nameTable.Add(docTypeName));
            }
            else
            {
                _schemaInfo.DocTypeName = new XmlQualifiedName(_nameTable.Add(docTypeName.Substring(0, colonPos)),
                                                               _nameTable.Add(docTypeName.Substring(colonPos + 1)));
            }

            int i;
            // check system id
            if (systemId != null && systemId.Length > 0)
            {
                if ((i = _xmlCharType.IsOnlyCharData(systemId)) >= 0)
                {
                    ThrowInvalidChar(_curPos, systemId, i);
                }
                _systemId = systemId;
            }

            // check public id
            if (publicId != null && publicId.Length > 0)
            {
                if ((i = _xmlCharType.IsPublicId(publicId)) >= 0)
                {
                    ThrowInvalidChar(_curPos, publicId, i);
                }
                _publicId = publicId;
            }

            // init free-floating internal subset
            if (internalSubset != null && internalSubset.Length > 0)
            {
                _readerAdapter.PushInternalDtd(baseUri, internalSubset);
                _hasFreeFloatingInternalSubset = true;
            }

            Uri baseUriOb = _readerAdapter.BaseUri;
            if (baseUriOb != null)
            {
                _documentBaseUri = baseUriOb.ToString();
            }

            _freeFloatingDtd = true;
        }
Example #5
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;
        }
        internal DtdParser( string baseUri, string docTypeName, string publicId, string systemId, string internalSubset, IDtdParserAdapter underlyingReader ) 
            : this( underlyingReader ) {

            if ( docTypeName == null || docTypeName.Length == 0 ) {
                throw XmlConvert.CreateInvalidNameArgumentException( docTypeName, "docTypeName" );
            }

            // check doctype name
            XmlConvert.VerifyName( docTypeName );
            int colonPos = docTypeName.IndexOf( ':' );
            if ( colonPos == -1 ) {
                schemaInfo.DocTypeName = new XmlQualifiedName( nameTable.Add( docTypeName ) );
            }
            else {
                schemaInfo.DocTypeName = new XmlQualifiedName( nameTable.Add( docTypeName.Substring( 0, colonPos ) ),
                                                               nameTable.Add( docTypeName.Substring( colonPos + 1 ) ) );
            }
            
            int i;
            // check system id
            if ( systemId != null && systemId.Length > 0 ) {
                if ( ( i = xmlCharType.IsOnlyCharData( systemId ) ) >= 0 ) {
                    ThrowInvalidChar( curPos, systemId[i] );
                }
                this.systemId = systemId;
            }

            // check public id
            if ( publicId != null && publicId.Length > 0 ) {
                if ( ( i = xmlCharType.IsPublicId( publicId ) ) >= 0 ) {
                    ThrowInvalidChar( curPos, publicId[i] );
                }
                this.publicId = publicId;
            }

            // init free-floating internal subset
            if ( internalSubset != null && internalSubset.Length > 0 ) {
                readerAdapter.PushInternalDtd( baseUri, internalSubset );
                hasFreeFloatingInternalSubset = true;
            }

            Uri baseUriOb = readerAdapter.BaseUri;
            if ( baseUriOb != null ) {
                documentBaseUri = baseUriOb.ToString();
            }

            freeFloatingDtd = true;
        }
        internal DtdParser( IDtdParserAdapter readerAdapter ) {
            Debug.Assert( readerAdapter != null );
            this.readerAdapter = readerAdapter;
            
            nameTable = readerAdapter.NameTable;

            validate =  readerAdapter.DtdValidation;
            normalize = readerAdapter.Normalization;
            supportNamespaces = readerAdapter.Namespaces;
            v1Compat = readerAdapter.V1CompatibilityMode;
            
            schemaInfo = new SchemaInfo();
            schemaInfo.SchemaType = SchemaType.DTD;
    
            stringBuilder = new BufferBuilder();

            Uri baseUri = readerAdapter.BaseUri;
            if ( baseUri != null ) {
                documentBaseUri = baseUri.ToString();
            }
        }
 internal void CheckDefaultValue(SchemaInfo schemaInfo, IDtdParserAdapter readerAdapter)
 {
     DtdValidator.CheckDefaultValue(this, schemaInfo, readerAdapter);
     defaultValueChecked = true;
 }
 async Task< IDtdInfo > IDtdParser.ParseFreeFloatingDtdAsync(string baseUri, string docTypeName, string publicId, string systemId, string internalSubset, IDtdParserAdapter adapter) {
     InitializeFreeFloatingDtd(baseUri, docTypeName, publicId, systemId, internalSubset, adapter);
     await ParseAsync(false).ConfigureAwait(false);
     return schemaInfo;
 }
        public static void CheckDefaultValue(
            SchemaAttDef        attdef,
            SchemaInfo          sinfo,
            IDtdParserAdapter   readerAdapter
        ) {
            try {
                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) {
                    Uri baseUri = readerAdapter.BaseUri;
                    string baseUriStr = ( baseUri == null ) ? string.Empty : baseUri.ToString();
                    if (dtype.Variety == XmlSchemaDatatypeVariety.List) {
                        string[] ss = (string[])typedValue;
                        foreach(string s in ss) {
                            ProcessEntity(sinfo, s, readerAdapter, readerAdapter.EventHandler, baseUriStr, attdef.ValueLineNum, attdef.ValueLinePos);
                        }
                    }
                    else {
                        ProcessEntity(sinfo, (string)typedValue, readerAdapter, readerAdapter.EventHandler, baseUriStr, attdef.ValueLineNum, attdef.ValueLinePos);
                    }
                }
                else if (ttype == XmlTokenizedType.ENUMERATION) {
                    if (!attdef.CheckEnumeration(typedValue)) {
                        XmlSchemaException e = new XmlSchemaException(Res.Sch_EnumerationValue, typedValue.ToString(), readerAdapter.BaseUri.ToString(), attdef.ValueLineNum, attdef.ValueLinePos);
                        readerAdapter.SendValidationEvent( XmlSeverityType.Error, e );
                    }
                }
            }
#if DEBUG
            catch (XmlSchemaException ex) {
                Debug.WriteLineIf(DiagnosticsSwitches.XmlSchema.TraceError, ex.Message);
#else
            catch (Exception)  {
#endif
                XmlSchemaException e = new XmlSchemaException(Res.Sch_AttributeDefaultDataType, attdef.Name.ToString());
                readerAdapter.SendValidationEvent( XmlSeverityType.Error, e );
            }
        }
Example #11
0
        //
        // Initialization methods
        //

        private void Initialize(IDtdParserAdapter readerAdapter)
        {
            Debug.Assert(readerAdapter != null);
            _readerAdapter = readerAdapter;

            _nameTable = readerAdapter.NameTable;


            _schemaInfo = new SchemaInfo();

            _stringBuilder = new BufferBuilder();

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

            _freeFloatingDtd = false;
        }
 public static void SetDefaultTypedValue(SchemaAttDef attdef, IDtdParserAdapter readerAdapter)
 {
     try
     {
         string defaultValueExpanded = attdef.DefaultValueExpanded;
         XmlSchemaDatatype datatype = attdef.Datatype;
         if (datatype != null)
         {
             if (datatype.TokenizedType != XmlTokenizedType.CDATA)
             {
                 defaultValueExpanded = defaultValueExpanded.Trim();
             }
             attdef.DefaultValueTyped = datatype.ParseValue(defaultValueExpanded, readerAdapter.NameTable, readerAdapter.NamespaceResolver);
         }
     }
     catch (Exception)
     {
         IValidationEventHandling validationEventHandling = ((IDtdParserAdapterWithValidation) readerAdapter).ValidationEventHandling;
         if (validationEventHandling != null)
         {
             XmlSchemaException exception = new XmlSchemaException("Sch_AttributeDefaultDataType", attdef.Name.ToString());
             validationEventHandling.SendEvent(exception, XmlSeverityType.Error);
         }
     }
 }
        public static void SetDefaultTypedValue(
            SchemaAttDef        attdef,
            IDtdParserAdapter   readerAdapter
        ) {
            try {
                string value = attdef.DefaultValueExpanded;
                XmlSchemaDatatype dtype = attdef.Datatype;
                if (dtype == null) {
                    return; // no reason to check
                }
                if (dtype.TokenizedType != XmlTokenizedType.CDATA) {
                    value = value.Trim();
                }
                attdef.DefaultValueTyped = dtype.ParseValue(value, readerAdapter.NameTable, readerAdapter.NamespaceResolver);
            }
#if DEBUG
            catch (XmlSchemaException ex) {
                Debug.WriteLineIf(DiagnosticsSwitches.XmlSchema.TraceError, ex.Message);
#else
            catch (Exception)  {
#endif
                IValidationEventHandling eventHandling = ((IDtdParserAdapterWithValidation)readerAdapter).ValidationEventHandling;
                if (eventHandling != null) {
                    XmlSchemaException e = new XmlSchemaException(Res.Sch_AttributeDefaultDataType, attdef.Name.ToString());
                    eventHandling.SendEvent(e, XmlSeverityType.Error);
                }
            }
        }
Example #14
0
        //
        // IDtdParser interface
        //
        #region IDtdParser Members

        IDtdInfo IDtdParser.ParseInternalDtd(IDtdParserAdapter adapter, bool saveInternalSubset)
        {
            Initialize(adapter);
            Parse(saveInternalSubset);
            return _schemaInfo;
        }
//
// IDtdParser interface
//
#region IDtdParser Members

        async Task< IDtdInfo > IDtdParser.ParseInternalDtdAsync(IDtdParserAdapter adapter, bool saveInternalSubset) {
            Initialize(adapter);
            await ParseAsync(saveInternalSubset).ConfigureAwait(false);
            return schemaInfo;
        }
Example #16
0
 IDtdInfo IDtdParser.ParseFreeFloatingDtd(string baseUri, string docTypeName, string publicId, string systemId, string internalSubset, IDtdParserAdapter adapter)
 {
     InitializeFreeFloatingDtd(baseUri, docTypeName, publicId, systemId, internalSubset, adapter);
     Parse(false);
     return _schemaInfo;
 }
 internal void CheckDefaultValue( SchemaInfo schemaInfo, IDtdParserAdapter readerAdapter ) {
     DtdValidator.CheckDefaultValue( this, schemaInfo, readerAdapter );
     defaultValueChecked = true;
 }