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; }
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); }