/// <summary>
        ///     Returns the XmlSchemaElement specified by the given qname defined in the given particle.
        /// </summary>
        /// <param name="particle"></param>
        /// <param name="qname"></param>
        /// <returns></returns>
        private XmlSchemaElement GetXmlSchemaElementFromParticle(XmlSchemaParticle particle, XmlQualifiedName qname)
        {
            XmlSchemaElement xe = null;
            var xsgb            = particle as XmlSchemaGroupBase;
            var xsgr            = particle as XmlSchemaGroupRef;

            if (xsgb != null)
            {
                xe = GetXmlElementFromXmlSchemaGroupBase(xsgb, qname);
            }
            else if (xsgr != null)
            {
                xe = GetXmlElementFromXmlSchemaGroupBase(xsgr.Particle, qname);
            }
            else if (particle != null)
            {
                Debug.Fail("Unable to handle case where particle type is " + particle.GetType());
            }
            return(xe);
        }
Example #2
0
        private string GetParticleDesc(XmlSchemaParticle particle)
        {
            var desc = particle.GetType().Name.Replace("XmlSchema", "");

            if (particle is XmlSchemaElement)
            {
                desc += "(" + ((XmlSchemaElement)particle).QualifiedName + ")";
            }
            if (particle.SourceUri == null)
            {
                if (particle.Id != null)
                {
                    return(string.Format("{0}:id:{1}", desc, particle.Id));
                }
                return(string.Format("{0}:{1}:{2}", desc, particle.LineNumber, particle.LinePosition));
            }
            else
            {
                string[] segments = new Uri(particle.SourceUri).Segments;
                return(string.Format("{0}:{1}:{2}:{3}", segments[segments.Length - 1], desc, particle.LineNumber, particle.LinePosition));
            }
        }
Example #3
0
        XmlQualifiedName ParseElement(XmlSchemaElement element, bool isTopLevel = false)
        {
            log.WriteLine("Found element {0}", GetParticleDesc(element));

            if (element.RefName != null && !element.RefName.IsEmpty)
            {
                return(element.RefName);
            }

            TempXmlElement tempXmlElement;

            if (elements.TryGetValue(element, out tempXmlElement))
            {
                // TODO detect real equals or conflict, if conflict merge
                return(element.QualifiedName);
            }

            tempXmlElement                           = new TempXmlElement();
            tempXmlElement.element                   = new SimpleXmlElement();
            tempXmlElement.element.Name              = element.QualifiedName.Name;
            tempXmlElement.element.Namespace         = element.QualifiedName.Namespace;
            tempXmlElement.element.IsTopLevelElement = isTopLevel;

            elements.Add(element, tempXmlElement);

            List <SimpleXmlAttribute> attributes = new List <SimpleXmlAttribute>();

            // if the element is a simple type, it cannot have attributes of children, thus ignore it
            // if the element is a complex type, we'll parse it.
            if (element.ElementSchemaType is XmlSchemaComplexType)
            {
                XmlSchemaComplexType type = (XmlSchemaComplexType)element.ElementSchemaType;
                using (log.Indent())
                {
                    log.WriteLine("Attributes");
                    using (log.Indent())
                    {
                        foreach (XmlSchemaAttribute attribute in type.AttributeUses.Values)
                        {
                            attributes.Add(ParseAttribute(attribute));
                            log.WriteLine("{0}", attribute.QualifiedName.Name);
                        }
                    }

                    XmlSchemaParticle particle = type.ContentTypeParticle;
                    if (particle != null)
                    {
                        log.WriteLine("Child Particle {0}", GetParticleDesc(particle));
                        using (log.Indent())
                        {
                            if (particle is XmlSchemaGroupRef)
                            {
                                tempXmlElement.children = ParseGoupRef((XmlSchemaGroupRef)particle);
                            }
                            else if (particle is XmlSchemaGroupBase)
                            {
                                tempXmlElement.children = ParseGroupBase((XmlSchemaGroupBase)particle);
                            }
                            else if (particle.GetType().Name == "EmptyParticle")
                            {
                            }
                            else
                            {
                                throw new NotImplementedException(particle.GetType().Name);
                            }
                        }
                    }
                }
            }

            tempXmlElement.element.Attributes = attributes;

            // TODO merge attrs and children on conflicts

            return(element.QualifiedName);
        }