Пример #1
0
            internal void AddChildValue(XmlElementValue value)
            {
                if (this.childValues == null)
                {
                    this.childValues = new List <XmlElementValue>();
                }

                this.childValues.Add(value);
            }
Пример #2
0
 internal static IEnumerable <XmlElementValue <T> > OfResultType <T>(this IEnumerable <XmlElementValue> elements)
     where T : class
 {
     foreach (var element in elements)
     {
         XmlElementValue <T> result = element as XmlElementValue <T>;
         if (result != null)
         {
             yield return(result);
         }
         else if (element.UntypedValue is T)
         {
             yield return(new XmlElementValue <T>(element.Name, element.Location, element.ValueAs <T>()));
         }
     }
 }
Пример #3
0
        private void EndElement()
        {
            ElementScope scope = this.currentBranch.Pop();

            this.currentScope = this.currentBranch.Count > 0 ? this.currentBranch.Peek() : null;

            XmlElementParser parser      = scope.Parser;
            XmlElementValue  resultValue = parser.Parse(scope.Element, scope.ChildValues);

            if (resultValue != null)
            {
                if (this.currentScope != null)
                {
                    this.currentScope.AddChildValue(resultValue);
                }
                else
                {
                    this.Result = resultValue;
                }
            }

            foreach (var unused in scope.Element.Attributes.Unused)
            {
                // there's no handler for (namespace,name) and there wasn't a validation error.
                // Report an error of our own if the node is in no namespace or if it is in one of our xml schemas target namespace.
                this.ReportUnexpectedAttribute(unused.Location, unused.Name);
            }

            // For text nodes, one may be expected but additional text should cause an error.
            var textNodes  = scope.ChildValues.Where(v => v.IsText);
            var unusedText = textNodes.Where(t => !t.IsUsed);

            if (unusedText.Any())
            {
                XmlTextValue firstInvalidText;
                if (unusedText.Count() == textNodes.Count())
                {
                    // Text is not expected at all for this element
                    firstInvalidText = (XmlTextValue)textNodes.First();
                }
                else
                {
                    // Additional text was unexpected
                    firstInvalidText = (XmlTextValue)unusedText.First();
                }

                this.ReportTextNotAllowed(firstInvalidText.Location, firstInvalidText.Value);
            }

            // If any elements were unused, the csdl is not properly formed. This could be a result of an entirely unexpected element
            // or, it could be an expected but superfluous element.
            // Consider:
            // <ReferentialConstraint>
            //     <Principal>... </Principal>
            //     <Dependent>... </Dependent>
            //     <Principal>... </Principal>
            // </ReferentialConstraint>
            //
            // The second occurrence of 'Principal' will be successfully parsed, but the element parser for ReferentialConstraint will not use its value because only the first occurence is expected.
            // This will also catch if only a single type reference (Collection, EntityReference) element was expected but multiple are provided
            foreach (var unusedChildValue in scope.ChildValues.Where(v => !v.IsText && !v.IsUsed))
            {
                this.ReportUnusedElement(unusedChildValue.Location, unusedChildValue.Name);
            }
        }