Esempio n. 1
0
        /// <summary>
        ///     Processes the model group.
        /// </summary>
        /// <param name="xsModel">The schema model.</param>
        /// <param name="xsObject">The schema that represents the model group.</param>
        /// <param name="simpleElements">The simple elements.</param>
        /// <param name="complexElements">The complex elements.</param>
        /// <param name="node">The node.</param>
        /// <param name="complexActualElement">The complex actual element.</param>
        /// <param name="complexElement">The complex element.</param>
        /// <returns></returns>
        private SchemaElementComplex ProcessModelGroup(
            XmlSchema xsModel,
            XmlSchemaObject xsObject,
            IList <SchemaElementSimple> simpleElements,
            IList <SchemaElementComplex> complexElements,
            ElementPathNode node,
            XmlSchemaComplexType complexActualElement,
            SchemaElementComplex complexElement)
        {
            var xsGroup = xsObject as XmlSchemaGroupBase;

            if (xsGroup != null)
            {
                return(ProcessModelGroup(
                           xsModel,
                           xsGroup.Items.Cast <XmlSchemaObject>(),
                           simpleElements,
                           complexElements,
                           node,
                           complexActualElement,
                           complexElement));
            }

            return(complexElement);
        }
Esempio n. 2
0
 public ElementPathNode(
     ElementPathNode parent,
     XmlQualifiedName name)
 {
     Name = name;
     Parent = parent;
 }
Esempio n. 3
0
        private SchemaElementComplex Process(
            XmlSchema xsModel,
            XmlQualifiedName complexElementName,
            XmlSchemaComplexType complexActualElement,
            bool isArray,
            ElementPathNode node)
        {
            if (Log.IsDebugEnabled)
            {
                Log.Debug(
                    "Processing complex {0} {1} stack {2}",
                    complexElementName.Namespace,
                    complexElementName.Name,
                    node);
            }

            var attributes      = new List <SchemaItemAttribute>();
            var simpleElements  = new List <SchemaElementSimple>();
            var complexElements = new List <SchemaElementComplex>();

            XmlSchemaSimpleType optionalSimpleType     = null;
            XmlQualifiedName    optionalSimpleTypeName = null;

            DetermineOptionalSimpleType(
                xsModel,
                complexActualElement,
                out optionalSimpleType,
                out optionalSimpleTypeName
                );

            var complexElement = new SchemaElementComplex(
                complexElementName.Name,
                complexElementName.Namespace,
                attributes,
                complexElements,
                simpleElements,
                isArray,
                optionalSimpleType,
                optionalSimpleTypeName);

            // add attributes
            attributes.AddRange(GetAttributes(xsModel, complexActualElement));

            var complexParticles = GetContentModelParticles(
                xsModel,
                complexActualElement);

            complexElement = ProcessModelGroup(
                xsModel,
                complexParticles,
                simpleElements,
                complexElements,
                node,
                complexActualElement,
                complexElement);

            return(complexElement);
        }
Esempio n. 4
0
        private void Import(
            XmlSchema xsModel,
            Uri schemaLocation)
        {
            ImportNamespaces(xsModel);
            ImportIncludes(xsModel, schemaLocation, Import);

            BuildElementDictionary(xsModel);
            BuildTypeDictionary(xsModel);

            // get top-level complex elements
            foreach (var schemaElement in xsModel.Items.OfType <XmlSchemaElement>())
            {
                var schemaType = schemaElement.SchemaType;
                if (schemaType == null)
                {
                    var schemaTypeName = schemaElement.SchemaTypeName;
                    if (!Equals(schemaTypeName, XmlQualifiedName.Empty))
                    {
                        schemaType = ResolveSchemaType(xsModel, schemaTypeName);
                    }
                }

                var complexElementType = schemaType as XmlSchemaComplexType;
                if (complexElementType != null)
                {
                    var complexActualName = schemaElement.QualifiedName;
                    if (Equals(complexActualName, XmlQualifiedName.Empty))
                    {
                        complexActualName = new XmlQualifiedName(
                            schemaElement.Name,
                            xsModel.TargetNamespace);
                    }

                    var rootNode = new ElementPathNode(null, complexActualName);

                    if (Log.IsDebugEnabled)
                    {
                        Log.Debug(string.Format("Processing component {0}", complexActualName));
                    }

                    var complexElement = Process(
                        xsModel,
                        complexActualName,
                        complexElementType,
                        false,
                        rootNode);

                    if (Log.IsDebugEnabled)
                    {
                        Log.Debug("Adding component {0}", complexActualName);
                    }

                    _components.Add(complexElement);
                }
            }
        }
Esempio n. 5
0
        public ElementPathNode AddChild(XmlQualifiedName name)
        {
            if (_children == null) {
                _children = new List<ElementPathNode>();
            }

            var newChild = new ElementPathNode(this, name);
            _children.Add(newChild);
            return newChild;
        }
Esempio n. 6
0
        /// <summary>
        ///     Processes the model group.
        /// </summary>
        /// <param name="xsModel">The schema model.</param>
        /// <param name="childParticles">The schema objects in this model group.</param>
        /// <param name="simpleElements">The simple elements.</param>
        /// <param name="complexElements">The complex elements.</param>
        /// <param name="node">The node.</param>
        /// <param name="complexActualElement">The complex actual element.</param>
        /// <param name="complexElement">The complex element.</param>
        /// <returns></returns>
        private SchemaElementComplex ProcessModelGroup(
            XmlSchema xsModel,
            IEnumerable <XmlSchemaObject> childParticles,
            IList <SchemaElementSimple> simpleElements,
            IList <SchemaElementComplex> complexElements,
            ElementPathNode node,
            XmlSchemaComplexType complexActualElement,
            SchemaElementComplex complexElement)
        {
            foreach (var childParticle in childParticles)
            {
                if (childParticle is XmlSchemaElement)
                {
                    var schemaElement = (XmlSchemaElement)childParticle;
                    var isArrayFlag   = IsArray(schemaElement);

                    // the name for this element
                    XmlQualifiedName elementName;
                    // the type for this element ... this may take different paths
                    // depending upon how the type is provided to us.
                    XmlSchemaType    schemaType;
                    XmlQualifiedName schemaTypeName;

                    if (schemaElement.RefName.IsEmpty)
                    {
                        elementName = schemaElement.QualifiedName;
                        if (Equals(elementName, XmlQualifiedName.Empty))
                        {
                            elementName = new XmlQualifiedName(
                                schemaElement.Name,
                                xsModel.TargetNamespace);
                        }

                        schemaType     = schemaElement.SchemaType;
                        schemaTypeName = schemaElement.SchemaTypeName;
                        if (schemaType == null && !schemaTypeName.IsEmpty)
                        {
                            schemaType = ResolveSchemaType(xsModel, schemaTypeName);
                        }
                    }
                    else
                    {
                        // this element contains a reference to another element... the element will
                        // share the name of the reference and the type of the reference.  the reference
                        // type should be a complex type.
                        var referenceElement     = ResolveElement(schemaElement.RefName);
                        var referenceElementType = referenceElement.SchemaType;

                        var elementNamespace = string.IsNullOrEmpty(schemaElement.RefName.Namespace)
                            ? xsModel.TargetNamespace
                            : schemaElement.RefName.Namespace;
                        elementName = new XmlQualifiedName(
                            schemaElement.RefName.Name,
                            elementNamespace);

                        schemaType     = referenceElementType;
                        schemaTypeName = referenceElement.SchemaTypeName;
                        // TODO
                    }

                    var simpleType = schemaType as XmlSchemaSimpleType;
                    if (simpleType != null)
                    {
                        var fractionDigits = GetFractionRestriction(simpleType);
                        var simpleElement  = new SchemaElementSimple(
                            elementName.Name,
                            elementName.Namespace,
                            simpleType,
                            schemaTypeName.Name,
                            isArrayFlag,
                            fractionDigits);
                        simpleElements.Add(simpleElement);
                    }
                    else
                    {
                        var complexType = schemaType as XmlSchemaComplexType;
                        var newChild    = node.AddChild(elementName);
                        if (newChild.DoesNameAlreadyExistInHierarchy())
                        {
                            continue;
                        }

                        complexActualElement = complexType;

                        var innerComplex = Process(
                            xsModel,
                            elementName,
                            complexActualElement,
                            isArrayFlag,
                            newChild
                            );

                        if (Log.IsDebugEnabled)
                        {
                            Log.Debug("Adding complex {0}", complexElement);
                        }

                        complexElements.Add(innerComplex);
                    }
                }

                ProcessModelGroup(
                    xsModel,
                    childParticle,
                    simpleElements,
                    complexElements,
                    node,
                    complexActualElement,
                    complexElement);
            }

            return(complexElement);
        }