The purpose of the DatatypeDefinitionXHTML class is to define XHTML formatted data.
Inheritance: ReqIFSharp.DatatypeDefinition
        /// <summary>
        /// Generates a <see cref="AttributeDefinitionXHTML"/> object from its XML representation.
        /// </summary>
        /// <param name="reader">
        /// an instance of <see cref="XmlReader"/>
        /// </param>
        public override void ReadXml(XmlReader reader)
        {
            base.ReadXml(reader);

            while (reader.Read())
            {
                if (reader.MoveToContent() == XmlNodeType.Element && reader.LocalName == "ALTERNATIVE-ID")
                {
                    var alternativeId = new AlternativeId(this);
                    alternativeId.ReadXml(reader);
                }

                if (reader.MoveToContent() == XmlNodeType.Element && reader.LocalName == "DATATYPE-DEFINITION-XHTML-REF")
                {
                    var reference = reader.ReadElementContentAsString();

                    var datatypeDefinition = (DatatypeDefinitionXHTML)this.SpecType.ReqIFContent.DataTypes.SingleOrDefault(x => x.Identifier == reference);
                    this.Type = datatypeDefinition;
                }

                // read the default value if any
                if (reader.MoveToContent() == XmlNodeType.Element && reader.LocalName == "ATTRIBUTE-VALUE-XHTML")
                {
                    this.DefaultValue = new AttributeValueXHTML(this);
                    using (var valuesubtree = reader.ReadSubtree())
                    {
                        valuesubtree.MoveToContent();
                        this.DefaultValue.ReadXml(valuesubtree);
                    }
                }
            }
        }
        /// <summary>
        /// Sets the <see cref="DatatypeDefinitionXHTML"/>
        /// </summary>
        /// <param name="datatypeDefinition">
        /// The instance of <see cref="DatatypeDefinitionXHTML"/> that is to be set.
        /// </param>
        protected override void SetDatatypeDefinition(DatatypeDefinition datatypeDefinition)
        {
            if (datatypeDefinition.GetType() != typeof(DatatypeDefinitionXHTML))
            {
                throw new ArgumentException("datatypeDefinition must of type DatatypeDefinitionString");
            }

            this.Type = (DatatypeDefinitionXHTML)datatypeDefinition;
        }
Esempio n. 3
0
        /// <summary>
        /// Asynchronously generates a <see cref="AttributeDefinitionXHTML"/> object from its XML representation.
        /// </summary>
        /// <param name="reader">
        /// an instance of <see cref="XmlReader"/>
        /// </param>
        /// <param name="token">
        /// A cancellation token that can be used by other objects or threads to receive notice of cancellation.
        /// </param>
        internal override async Task ReadXmlAsync(XmlReader reader, CancellationToken token)
        {
            base.ReadXml(reader);

            while (await reader.ReadAsync())
            {
                if (token.IsCancellationRequested)
                {
                    token.ThrowIfCancellationRequested();
                }

                if (await reader.MoveToContentAsync() == XmlNodeType.Element)
                {
                    switch (reader.LocalName)
                    {
                    case "ALTERNATIVE-ID":
                        var alternativeId = new AlternativeId(this);
                        alternativeId.ReadXml(reader);
                        break;

                    case "DATATYPE-DEFINITION-XHTML-REF":
                        var reference = await reader.ReadElementContentAsStringAsync();

                        var datatypeDefinition = (DatatypeDefinitionXHTML)this.SpecType.ReqIFContent.DataTypes.SingleOrDefault(x => x.Identifier == reference);
                        this.Type = datatypeDefinition;

                        if (datatypeDefinition == null)
                        {
                            this.logger.LogTrace("The DatatypeDefinitionXHTML:{reference} could not be found and has been set to null on AttributeDefinitionXHTML:{Identifier}", reference, Identifier);
                        }

                        break;

                    case "ATTRIBUTE-VALUE-XHTML":
                        this.DefaultValue = new AttributeValueXHTML(this, this.loggerFactory);
                        using (var valueSubtree = reader.ReadSubtree())
                        {
                            await valueSubtree.MoveToContentAsync();

                            await this.DefaultValue.ReadXmlAsync(valueSubtree, token);
                        }
                        break;
                    }
                }
            }
        }