Exemple #1
0
        internal XSAttributeDeclaration(XmlSchemaAttribute xmlAttribute)
            : this()
        {
            _attribute = xmlAttribute;

            if (_attribute.Annotation is XmlSchemaAnnotation annotation)
            {
                _annotation = XMLSchemaSerializer.CreateXSAnnotation(annotation);
                _annotation.BindToContainer(RootContainer, this);
            }

            if (_attribute.SchemaTypeName is XmlQualifiedName schemaTypeName)
            {
                _typeName = XMLSchemaSerializer.CreateXMLExpandedName(schemaTypeName);
            }

            if (_attribute.RefName is XmlQualifiedName refName)
            {
                _refName = XMLSchemaSerializer.CreateXMLExpandedName(refName);
            }

            if (_attribute.SchemaType is XmlSchemaSimpleType schemaType)
            {
                _schemaType = XMLSchemaSerializer.CreateXSSimpleTypeDefinition(schemaType);
            }
        }
        internal XSElementDeclaration(XmlSchemaElement element)
            : this()
        {
            _element = element;

            if (_element.Annotation is XmlSchemaAnnotation annotation)
            {
                _annotation = XMLSchemaSerializer.CreateXSAnnotation(annotation);
                _annotation.BindToContainer(RootContainer, this);
            }

            if (element.SchemaTypeName is XmlQualifiedName schemaTypeName)
            {
                _typeName = XMLSchemaSerializer.CreateXMLExpandedName(schemaTypeName);
            }

            if (element.RefName is XmlQualifiedName refName)
            {
                _refName = XMLSchemaSerializer.CreateXMLExpandedName(refName);
            }

            if (element.SubstitutionGroup is XmlQualifiedName substitutionGroup)
            {
                _substitutionGroup = XMLSchemaSerializer.CreateXMLExpandedName(substitutionGroup);
            }

            if (_element.SchemaType is XmlSchemaType schemaType)
            {
                _schemaType = XMLSchemaSerializer.CreateIXSType(schemaType);
            }
        }
Exemple #3
0
        public void WriteXML(XmlWriterImpl xmlWriter,
                             IValue value,
                             string name,
                             XMLTypeAssignment typeAssigment = XMLTypeAssignment.Implicit,
                             XMLForm form = XMLForm.Element)
        {
            XMLExpandedName xmlType;

            switch (value.DataType)
            {
            case DataType.Undefined:

                WriteXMLUndefined(xmlWriter, name, form);
                break;

            case DataType.String:

                xmlType = new XMLExpandedName(XmlSchema.InstanceNamespace, "string");
                WriteXMLSimpleData(xmlWriter, name, value, xmlType, typeAssigment, form);
                break;

            case DataType.Number:

                xmlType = new XMLExpandedName(XmlSchema.InstanceNamespace, "decimal");
                WriteXMLSimpleData(xmlWriter, name, value, xmlType, typeAssigment, form);
                break;

            case DataType.Boolean:

                xmlType = new XMLExpandedName(XmlSchema.InstanceNamespace, "boolean");
                WriteXMLSimpleData(xmlWriter, name, value, xmlType, typeAssigment, form);
                break;

            case DataType.Date:

                xmlType = new XMLExpandedName(XmlSchema.InstanceNamespace, "dateTime");
                WriteXMLSimpleData(xmlWriter, name, value, xmlType, typeAssigment, form);
                break;

            case DataType.Object:

                IRuntimeContextInstance valueObject = value.AsObject();
                if (valueObject is IXDTOSerializableXML seriazable)
                {
                    seriazable.WriteXML(xmlWriter, this);
                }
                else
                {
                    throw RuntimeException.InvalidArgumentType();
                }
                break;

            default:
                throw RuntimeException.InvalidArgumentType();
            }
        }
        internal XSSimpleTypeDefinition(XmlSchemaSimpleType simpleType)
            : this()
        {
            _type = simpleType;

            if (_type.Annotation is XmlSchemaAnnotation annotation)
            {
                _annotation = XMLSchemaSerializer.CreateXSAnnotation(annotation);
                _annotation.BindToContainer(RootContainer, this);
            }

            if (_type.Content is XmlSchemaSimpleTypeList typeList)
            {
                _variety = XSSimpleTypeVariety.List;

                if (typeList.ItemTypeName is XmlQualifiedName qualifiedName)
                {
                    _itemTypeName = new XMLExpandedName(qualifiedName);
                }
            }
            else if (_type.Content is XmlSchemaSimpleTypeUnion typeUnion)
            {
                _variety = XSSimpleTypeVariety.Union;

                MemberTypeDefinitions.Inserted -= MemberTypeDefinitions_Inserted;
                foreach (XmlSchemaObject item in typeUnion.BaseTypes)
                {
                    IXSComponent component = XMLSchemaSerializer.CreateInstance(item);
                    component.BindToContainer(RootContainer, this);
                    MemberTypeDefinitions.Add(component);
                    Components.Add(component);
                }
                MemberTypeDefinitions.Inserted += MemberTypeDefinitions_Inserted;
            }
            else if (_type.Content is XmlSchemaSimpleTypeRestriction typeRestriction)
            {
                _variety = XSSimpleTypeVariety.Atomic;

                if (typeRestriction.BaseTypeName is XmlQualifiedName qualifiedName)
                {
                    _baseTypeName = new XMLExpandedName(qualifiedName);
                }

                Facets.Inserted -= Facets_Inserted;
                foreach (XmlSchemaObject item in typeRestriction.Facets)
                {
                    IXSComponent component = XMLSchemaSerializer.CreateInstance(item);
                    component.BindToContainer(RootContainer, this);
                    Facets.Add(component);
                    Components.Add(component);
                }
                Facets.Inserted += Facets_Inserted;
            }
        }
Exemple #5
0
        internal XSModelGroupDefinition(XmlSchemaGroupRef xmlGroupRef)
        {
            _group = xmlGroupRef;

            if (_group.Annotation is XmlSchemaAnnotation annotation)
            {
                _annotation = XMLSchemaSerializer.CreateXSAnnotation(annotation);
                _annotation.BindToContainer(RootContainer, this);
            }

            if (xmlGroupRef.RefName is XmlQualifiedName qualifiedName)
            {
                _reference = XMLSchemaSerializer.CreateXMLExpandedName(qualifiedName);
            }
        }
Exemple #6
0
        private void WriteXMLSimpleData(XmlWriterImpl xmlWriter,
                                        string name,
                                        IValue value,
                                        XMLExpandedName type,
                                        XMLTypeAssignment typeAssigment,
                                        XMLForm form)
        {
            XmlNamespaceContext namespaceContext;
            string xmlValue = XMLString(value);

            switch (form)
            {
            case XMLForm.Attribute:
                namespaceContext = xmlWriter.NamespaceContext;
                AddNamespaceMapping(namespaceContext, xmlWriter, "", XmlSchema.Namespace);

                xmlWriter.WriteStartAttribute(name);
                xmlWriter.WriteText(xmlValue);
                xmlWriter.WriteEndAttribute();
                break;

            case XMLForm.Text:
                xmlWriter.WriteText(xmlValue);
                break;

            default:

                xmlWriter.WriteStartElement(name);

                namespaceContext = xmlWriter.NamespaceContext;
                AddNamespaceMapping(namespaceContext, xmlWriter, "", XmlSchema.Namespace);
                AddNamespaceMapping(namespaceContext, xmlWriter, "xsi", XmlSchema.InstanceNamespace);

                if (typeAssigment == XMLTypeAssignment.Explicit)
                {
                    xmlWriter.WriteStartAttribute("type", XmlSchema.InstanceNamespace);
                    xmlWriter.WriteText(type.LocalName);
                    xmlWriter.WriteEndAttribute();
                }

                xmlWriter.WriteText(xmlValue);

                xmlWriter.WriteEndElement();
                break;
            }
        }
Exemple #7
0
        internal XSComplexTypeDefinition(XmlSchemaComplexType complexType)
            : this()
        {
            _type = complexType;

            if (_type.Annotation is XmlSchemaAnnotation annotation)
            {
                _annotation = XMLSchemaSerializer.CreateXSAnnotation(annotation);
                _annotation.BindToContainer(RootContainer, this);
            }

            if (_type.ContentModel is XmlSchemaSimpleContent simpleContent)
            {
                _contentModel = XSContentModel.Simple;
                if (simpleContent.Content is XmlSchemaSimpleContentExtension contentExtension)
                {
                    _derivationMethod = XSDerivationMethod.Extension;
                    if (contentExtension.BaseTypeName is XmlQualifiedName qualifiedName)
                    {
                        _baseTypeName = XMLSchemaSerializer.CreateXMLExpandedName(qualifiedName);
                    }

                    if (contentExtension.AnyAttribute is XmlSchemaAnyAttribute anyAttribute)
                    {
                        _attributeWildcard = XMLSchemaSerializer.CreateXSWildcard(anyAttribute);
                    }
                }
                else if (simpleContent.Content is XmlSchemaSimpleContentRestriction contentRestriction)
                {
                    _derivationMethod = XSDerivationMethod.Restriction;
                    if (contentRestriction.BaseTypeName is XmlQualifiedName qualifiedName)
                    {
                        _baseTypeName = XMLSchemaSerializer.CreateXMLExpandedName(qualifiedName);
                    }

                    if (contentRestriction.AnyAttribute is XmlSchemaAnyAttribute anyAttribute)
                    {
                        _attributeWildcard = XMLSchemaSerializer.CreateXSWildcard(anyAttribute);
                    }
                }
                else
                {
                    _derivationMethod = XSDerivationMethod.EmptyRef;
                }

                if (_type.Particle is XmlSchemaParticle particle)
                {
                    _content = XMLSchemaSerializer.CreateInstance(particle);
                }
            }
            else if (_type.ContentModel is XmlSchemaComplexContent complexContent)
            {
                _contentModel = XSContentModel.Complex;

                if (complexContent.Content is XmlSchemaComplexContentExtension contentExtension)
                {
                    _derivationMethod = XSDerivationMethod.Extension;
                    if (contentExtension.BaseTypeName is XmlQualifiedName qualifiedName)
                    {
                        _baseTypeName = XMLSchemaSerializer.CreateXMLExpandedName(qualifiedName);
                    }

                    if (contentExtension.Particle is XmlSchemaParticle particle)
                    {
                        _content = XMLSchemaSerializer.CreateInstance(particle);
                    }

                    if (contentExtension.AnyAttribute is XmlSchemaAnyAttribute anyAttribute)
                    {
                        _attributeWildcard = XMLSchemaSerializer.CreateXSWildcard(anyAttribute);
                    }
                }
                else if (complexContent.Content is XmlSchemaComplexContentRestriction contentRestriction)
                {
                    _derivationMethod = XSDerivationMethod.Restriction;
                    if (contentRestriction.BaseTypeName is XmlQualifiedName qualifiedName)
                    {
                        _baseTypeName = XMLSchemaSerializer.CreateXMLExpandedName(qualifiedName);
                    }

                    if (contentRestriction.Particle is XmlSchemaParticle particle)
                    {
                        _content = XMLSchemaSerializer.CreateInstance(particle);
                    }

                    if (contentRestriction.AnyAttribute is XmlSchemaAnyAttribute anyAttribute)
                    {
                        _attributeWildcard = XMLSchemaSerializer.CreateXSWildcard(anyAttribute);
                    }
                }
                else
                {
                    _derivationMethod = XSDerivationMethod.EmptyRef;

                    if (_type.Particle is XmlSchemaParticle particle)
                    {
                        _content = XMLSchemaSerializer.CreateInstance(particle);
                    }
                }
            }
            else
            {
                _contentModel = XSContentModel.EmptyRef;

                if (_type.Particle is XmlSchemaParticle particle)
                {
                    _content = XMLSchemaSerializer.CreateInstance(particle);
                }
            }

            Attributes.Inserted -= Attributes_Inserted;
            foreach (XmlSchemaObject item in _type.Attributes)
            {
                IXSComponent component = XMLSchemaSerializer.CreateInstance(item);
                component.BindToContainer(RootContainer, this);
                Attributes.Add(component);
                Components.Add(component);
            }
            Attributes.Inserted += Attributes_Inserted;
        }