Beispiel #1
0
        private void BeginElement(XmlElementParser elementParser, XmlElementInfo element)
        {
            ElementScope newScope = new ElementScope(elementParser, element);

            this.currentBranch.Push(newScope);
            this.currentScope = newScope;
        }
        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);
        }
Beispiel #3
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)
                    {
                        int depth = reader.Depth;
                        do
                        {
                            reader.Read();
                        }while (reader.Depth > depth);
                    }

                    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));
                }
            }
        }
Beispiel #4
0
 internal ElementScope(XmlElementParser parser, XmlElementInfo element)
 {
     this.Parser  = parser;
     this.Element = element;
 }
Beispiel #5
0
 protected abstract bool TryGetRootElementParser(Version artifactVersion, XmlElementInfo rootElement, out XmlElementParser parser);
Beispiel #6
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();
            }
        }
 internal abstract XmlElementValue Parse(XmlElementInfo element, IList <XmlElementValue> children);
 internal static XmlAttributeInfo GetOptionalAttribute(XmlElementInfo element, string attributeName)
 {
     return(element.Attributes[attributeName]);
 }
 protected void EndItem()
 {
     this.elementStack.Pop();
     this.currentElement = this.elementStack.Count == 0 ? null : this.elementStack.Peek();
 }
 protected void BeginItem(XmlElementInfo element)
 {
     this.elementStack.Push(element);
     this.currentElement = element;
 }