Esempio n. 1
0
        private void BeginElement(XmlElementParser elementParser, XmlElementInfo element)
        {
            ElementScope newScope = new ElementScope(elementParser, element);

            this.currentBranch.Push(newScope);
            this.currentScope = newScope;
        }
Esempio n. 2
0
        internal void ParseDocumentElement()
        {
            Version version = null;

            string[]         strArrays        = null;
            XmlElementParser xmlElementParser = null;

            this.reader      = this.InitializeReader(this.reader);
            this.xmlLineInfo = this.reader as IXmlLineInfo;
            if (this.reader.NodeType != XmlNodeType.Element)
            {
                while (this.reader.Read() && this.reader.NodeType != XmlNodeType.Element)
                {
                }
            }
            if (!this.reader.EOF)
            {
                this.DocumentNamespace = this.reader.NamespaceURI;
                if (!this.TryGetDocumentVersion(this.DocumentNamespace, out version, out strArrays))
                {
                    this.ReportUnexpectedRootNamespace(this.reader.LocalName, this.DocumentNamespace, strArrays);
                    return;
                }
                else
                {
                    this.DocumentVersion         = version;
                    this.DocumentElementLocation = this.Location;
                    bool           isEmptyElement = this.reader.IsEmptyElement;
                    XmlElementInfo xmlElementInfo = this.ReadElement(this.reader.LocalName, this.DocumentElementLocation);
                    if (this.TryGetRootElementParser(this.DocumentVersion, xmlElementInfo, out xmlElementParser))
                    {
                        this.BeginElement(xmlElementParser, xmlElementInfo);
                        if (!isEmptyElement)
                        {
                            this.Parse();
                            return;
                        }
                        else
                        {
                            this.EndElement();
                            return;
                        }
                    }
                    else
                    {
                        this.ReportUnexpectedRootElement(xmlElementInfo.Location, xmlElementInfo.Name, this.DocumentNamespace);
                        return;
                    }
                }
            }
            else
            {
                this.ReportEmptyFile();
                return;
            }
        }
Esempio n. 3
0
        internal XmlAttributeInfo GetRequiredAttribute(XmlElementInfo element, string attributeName)
        {
            var attr = element.Attributes[attributeName];

            if (attr.IsMissing)
            {
                this.ReportError(element.Location, EdmErrorCode.MissingAttribute, Edm.Strings.XmlParser_MissingAttribute(attributeName, element.Name));
                return(attr);
            }

            return(attr);
        }
        internal XmlAttributeInfo GetRequiredAttribute(XmlElementInfo element, string attributeName)
        {
            XmlAttributeInfo item = element.Attributes[attributeName];

            if (!item.IsMissing)
            {
                return(item);
            }
            else
            {
                base.ReportError(element.Location, EdmErrorCode.MissingAttribute, Strings.XmlParser_MissingAttribute(attributeName, element.Name));
                return(item);
            }
        }
Esempio n. 5
0
        private void ProcessElement()
        {
            bool   emptyElement     = this.reader.IsEmptyElement;
            string elementNamespace = this.reader.NamespaceURI;
            string elementName      = this.reader.LocalName;

            if (elementNamespace == this.DocumentNamespace)
            {
                XmlElementParser newParser;

                if (!this.currentScope.Parser.TryGetChildElementParser(elementName, out newParser))
                {
                    this.ReportUnexpectedElement(this.Location, this.reader.Name);
                    if (!emptyElement)
                    {
                        this.reader.Read();
                    }

                    return;
                }

                XmlElementInfo newElement = this.ReadElement(elementName, this.Location);
                this.BeginElement(newParser, newElement);
                if (emptyElement)
                {
                    this.EndElement();
                }
            }
            else
            {
                // This element is not in the expected XML namespace for this artifact.
                // we need to report an error if the namespace for this element is a target namespace for the xml schemas we are parsing against.
                // otherwise we assume that this is either a valid 'any' element or that the xsd validator has generated an error
                if (string.IsNullOrEmpty(elementNamespace) || this.IsOwnedNamespace(elementNamespace))
                {
                    this.ReportUnexpectedElement(this.Location, this.reader.Name);
                    this.reader.Skip();
                }
                else
                {
                    XmlReader elementReader = this.reader.ReadSubtree();
                    elementReader.MoveToContent();
                    string annotationValue = elementReader.ReadOuterXml();
                    this.currentScope.Element.AddAnnotation(new XmlAnnotationInfo(this.Location, elementNamespace, elementName, annotationValue, false));
                }
            }
        }
Esempio n. 6
0
        private void ProcessElement()
        {
            XmlElementParser xmlElementParser = null;
            bool             isEmptyElement   = this.reader.IsEmptyElement;
            string           namespaceURI     = this.reader.NamespaceURI;
            string           localName        = this.reader.LocalName;

            if (namespaceURI != this.DocumentNamespace)
            {
                if (string.IsNullOrEmpty(namespaceURI) || this.IsOwnedNamespace(namespaceURI))
                {
                    this.ReportUnexpectedElement(this.Location, this.reader.Name);
                    this.reader.Skip();
                    return;
                }
                else
                {
                    XmlReader xmlReader = this.reader.ReadSubtree();
                    xmlReader.MoveToContent();
                    string str = xmlReader.ReadOuterXml();
                    this.currentScope.Element.AddAnnotation(new XmlAnnotationInfo(this.Location, namespaceURI, localName, str, false));
                }
            }
            else
            {
                if (this.currentScope.Parser.TryGetChildElementParser(localName, out xmlElementParser))
                {
                    XmlElementInfo xmlElementInfo = this.ReadElement(localName, this.Location);
                    this.BeginElement(xmlElementParser, xmlElementInfo);
                    if (isEmptyElement)
                    {
                        this.EndElement();
                        return;
                    }
                }
                else
                {
                    this.ReportUnexpectedElement(this.Location, this.reader.Name);
                    if (!isEmptyElement)
                    {
                        this.reader.Read();
                    }
                    return;
                }
            }
        }
Esempio n. 7
0
 private void BeginElement(XmlElementParser elementParser, XmlElementInfo element)
 {
     XmlDocumentParser.ElementScope elementScope = new XmlDocumentParser.ElementScope(elementParser, element);
     this.currentBranch.Push(elementScope);
     this.currentScope = elementScope;
 }
Esempio n. 8
0
 internal abstract XmlElementValue Parse(XmlElementInfo element, IList <XmlElementValue> children);
Esempio n. 9
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);
            }
        }
Esempio n. 10
0
 protected abstract bool TryGetDocumentElementParser(Version artifactVersion, XmlElementInfo rootElement, out XmlElementParser <TResult> parser);
Esempio n. 11
0
        internal override XmlElementValue Parse(XmlElementInfo element, IList <XmlElementValue> children)
        {
            TResult tResult = this.parserFunc(element, XmlElementValueCollection.FromList(children));

            return(new XmlElementValue <TResult>(element.Name, element.Location, tResult));
        }
Esempio n. 12
0
 internal XmlAttributeInfo GetOptionalAttribute(XmlElementInfo element, string attributeName)
 {
     return(element.Attributes[attributeName]);
 }
Esempio n. 13
0
 protected void BeginItem(XmlElementInfo element)
 {
     this.elementStack.Push(element);
     this.currentElement = element;
 }
Esempio n. 14
0
 protected abstract bool TryGetRootElementParser(Version artifactVersion, XmlElementInfo rootElement, out XmlElementParser parser);
Esempio n. 15
0
        internal void ParseDocumentElement()
        {
            Debug.Assert(this.DocumentNamespace == null && this.xmlLineInfo == null, "Calling MoveToDocumentElement more than once?");

            this.reader      = this.InitializeReader(this.reader);
            this.xmlLineInfo = this.reader as IXmlLineInfo;

            // To make life simpler, we skip down to the first/root element, unless we're
            // already there
            if (this.reader.NodeType != XmlNodeType.Element)
            {
                while (this.reader.Read() && this.reader.NodeType != XmlNodeType.Element)
                {
                }
            }

            // There must be a root element for all current artifacts
            if (this.reader.EOF)
            {
                this.ReportEmptyFile();
                return;
            }

            // The root element must be in an expected namespace that maps to a version of the input artifact type.
            this.DocumentNamespace = this.reader.NamespaceURI;
            Version discoveredVersion;

            string[] expectedNamespaces;
            if (this.TryGetDocumentVersion(this.DocumentNamespace, out discoveredVersion, out expectedNamespaces))
            {
                this.DocumentVersion = discoveredVersion;
            }
            else
            {
                this.ReportUnexpectedRootNamespace(this.reader.LocalName, this.DocumentNamespace, expectedNamespaces);
                return;
            }

            this.DocumentElementLocation = this.Location;

            // At this point the root element is in one of the expected namespaces but may not be the expected root element for that namespace
            bool             emptyElement = this.reader.IsEmptyElement;
            XmlElementInfo   rootElement  = this.ReadElement(this.reader.LocalName, this.DocumentElementLocation);
            XmlElementParser currentParser;

            if (!this.TryGetRootElementParser(this.DocumentVersion, rootElement, out currentParser))
            {
                this.ReportUnexpectedRootElement(rootElement.Location, rootElement.Name, this.DocumentNamespace);
                return;
            }

            this.BeginElement(currentParser, rootElement);
            if (emptyElement)
            {
                this.EndElement();
            }
            else
            {
                this.Parse();
            }
        }
Esempio n. 16
0
 internal ElementScope(XmlElementParser parser, XmlElementInfo element)
 {
     this.Parser  = parser;
     this.Element = element;
 }
Esempio n. 17
0
 protected void EndItem()
 {
     this.elementStack.Pop();
     this.currentElement = this.elementStack.Count == 0 ? null : this.elementStack.Peek();
 }