예제 #1
0
 public void AddChildParser(XmlElementParser child)
 {
     this.childParsers[child.ElementName] = child;
 }
예제 #2
0
 protected abstract bool TryGetDocumentElementParser(Version artifactVersion, XmlElementInfo rootElement, out XmlElementParser <TResult> parser);
예제 #3
0
        protected sealed override bool TryGetRootElementParser(Version artifactVersion, XmlElementInfo rootElement, out XmlElementParser parser)
        {
            XmlElementParser <TResult> xmlElementParser = null;

            if (!this.TryGetDocumentElementParser(artifactVersion, rootElement, out xmlElementParser))
            {
                parser = null;
                return(false);
            }
            else
            {
                parser = xmlElementParser;
                return(true);
            }
        }
예제 #4
0
 internal ElementScope(XmlElementParser parser, XmlElementInfo element)
 {
     this.Parser  = parser;
     this.Element = element;
 }
예제 #5
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 (Row, 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);
            }
        }
예제 #6
0
 protected virtual XmlElementParser <TResult> Element <TResult>(string elementName, Func <XmlElementInfo, XmlElementValueCollection, TResult> parserFunc, params XmlElementParser[] childParsers)
 {
     return(XmlElementParser.Create(elementName, parserFunc, childParsers, null));
 }
예제 #7
0
 protected abstract bool TryGetRootElementParser(Version artifactVersion, XmlElementInfo rootElement, out XmlElementParser parser);
예제 #8
0
 internal bool TryGetChildElementParser(string elementName, out XmlElementParser elementParser)
 {
     elementParser = null;
     return(this.childParsers != null && this.childParsers.TryGetValue(elementName, out elementParser));
 }