Example #1
0
        public XmlElement ParseElement(XElement element)
        {
            if (IsExternallyReferencedElement(element))
            {
                var typeName    = GetNameOfExternallyReferencedElement(element);
                var unknownType = _xmlUnknownTypeParser.GetUnknownTypeDefinitionByName(typeName);
                return(new XmlElement
                {
                    Name = typeName,
                    IsExternallyDeclared = true,
                    Type = unknownType
                });
            }
            if (IsInternallyReferencedElement(element))
            {
                var referencedElementName = element.Attributes().Single(a => a.Name == "ref").Value;
                var internalReference     = _document.Root?.Elements().Single(e => e.Name == _xmlSchemaNamespace + "element" && e.Attributes().Any(a => a.Name == "name" && a.Value == referencedElementName));
                return(ParseElement(internalReference));
            }
            var elementName = GetNameForElement(element);
            var elementType = ParseXmlType(element);
            var result      = new XmlElement
            {
                Name = elementName,
                Type = elementType
            };

            return(result);
        }
Example #2
0
        public XmlType ParseElement(XElement element)
        {
            if (IsUnknownType(element))
            {
                var unknownTypeName = element.Attributes().Single(a => a.Name == "type").Value;
                return(_xmlUnknownTypeParser.GetUnknownTypeDefinitionByName(unknownTypeName));
            }
            var typeDefinitionElement = GetTypeDefinitionElement(element);
            var typeName = GetTypeName(typeDefinitionElement);

            if (_simpleTypesByTypeName.ContainsKey(typeName))
            {
                return(_simpleTypesByTypeName[typeName]);
            }
            XmlSimpleType result;

            if (_enumerationRestrictionParser.IsEnumerationType(typeDefinitionElement))
            {
                var enumerationValues = _enumerationRestrictionParser.GetEnumerationValues(typeDefinitionElement);
                result = new XmlEnumerationType
                {
                    Name = typeName,
                    EnumerationValues = enumerationValues
                };
            }
            else
            {
                result = new XmlSimpleType
                {
                    Name = typeName
                };
            }
            _simpleTypesByTypeName.Add(typeName, result);
            return(result);
        }
Example #3
0
        private XmlAttribute GetAttributeForReferencedAttribute(XElement element)
        {
            var attributeReference = element.Attributes().Single(a => a.Name == "ref").Value;
            var localAttribute     = _document.Root?.Elements().FirstOrDefault(e => e.Name == _xmlSchemaNamespace + "attribute" && e.Attributes().Any(a => a.Name == "name" && a.Value == attributeReference));

            if (localAttribute == null)
            {
                var attributeType = _xmlUnknownTypeParser.GetUnknownTypeDefinitionByName(attributeReference);
                return(new XmlAttribute
                {
                    Name = attributeReference,
                    Type = attributeType
                });
            }
            return(GetAttributeForAttributeWithName(localAttribute));
        }