ParseObject() private method

private ParseObject ( XmlElement element ) : XamlObject
element XmlElement
return XamlObject
コード例 #1
0
        internal static XamlDocument Parse(XmlDocument document, XamlParserSettings settings)
        {
            if (document == null)
            {
                throw new ArgumentNullException("document");
            }
            if (settings == null)
            {
                throw new ArgumentNullException("settings");
            }
            XamlParser p = new XamlParser();

            p.settings  = settings;
            p.errorSink = (IXamlErrorSink)settings.ServiceProvider.GetService(typeof(IXamlErrorSink));
            p.document  = new XamlDocument(document, settings);

            try {
                var root = p.ParseObject(document.DocumentElement);
                p.document.ParseComplete(root);
            } catch (Exception x) {
                p.ReportException(x, document.DocumentElement);
            }

            return(p.document);
        }
コード例 #2
0
        /// <summary>
        /// Method use to parse a piece of Xaml.
        /// </summary>
        /// <param name="root">The Root XamlObject of the current document.</param>
        /// <param name="xaml">The Xaml being parsed.</param>
        /// <param name="settings">Parser settings used by <see cref="XamlParser"/>.</param>
        /// <returns>Returns the XamlObject of the parsed <paramref name="xaml"/>.</returns>
        public static XamlObject ParseSnippet(XamlObject root, string xaml, XamlParserSettings settings)
        {
            XmlTextReader reader  = new XmlTextReader(new StringReader(xaml));
            var           element = root.OwnerDocument.XmlDocument.ReadNode(reader);

            if (element != null)
            {
                XmlAttribute xmlnsAttribute = null;
                foreach (XmlAttribute attrib in element.Attributes)
                {
                    if (attrib.Name == "xmlns")
                    {
                        xmlnsAttribute = attrib;
                    }
                }
                if (xmlnsAttribute != null)
                {
                    element.Attributes.Remove(xmlnsAttribute);
                }

                RemoveRootNamespacesFromNodeAndChildNodes(root, element);

                XamlParser parser = new XamlParser();
                parser.settings = settings;
                parser.document = root.OwnerDocument;
                var xamlObject = parser.ParseObject(element as XmlElement);
                if (xamlObject != null)
                {
                    return(xamlObject);
                }
            }
            return(null);
        }
コード例 #3
0
        /// <summary>
        /// Method use to parse a piece of Xaml.
        /// </summary>
        /// <param name="root">The Root XamlObject of the current document.</param>
        /// <param name="xaml">The Xaml being parsed.</param>
        /// <param name="settings">Parser settings used by <see cref="XamlParser"/>.</param>
        /// <returns>Returns the XamlObject of the parsed <paramref name="xaml"/>.</returns>
        public static XamlObject ParseSnippet(XamlObject root, string xaml, XamlParserSettings settings)
        {
            XmlTextReader reader  = new XmlTextReader(new StringReader(xaml));
            var           element = root.OwnerDocument.XmlDocument.ReadNode(reader);

            if (element != null)
            {
                XmlAttribute xmlnsAttribute = null;
                foreach (XmlAttribute attrib in element.Attributes)
                {
                    if (attrib.Name == "xmlns")
                    {
                        xmlnsAttribute = attrib;
                    }
                }
                if (xmlnsAttribute != null)
                {
                    element.Attributes.Remove(xmlnsAttribute);
                }

                //Remove namespace Attributes defined in the Xaml Root from the Pasted Snippet!
                List <XmlAttribute> removeAttributes = new List <XmlAttribute>();
                foreach (XmlAttribute attrib in element.Attributes)
                {
                    if (attrib.Name.StartsWith("xmlns:"))
                    {
                        var rootPrefix = root.OwnerDocument.GetPrefixForNamespace(attrib.Value);
                        if (rootPrefix == null)
                        {
                            //todo: check if we can add to root, (maybe same ns exists)
                            root.OwnerDocument.XmlDocument.Attributes.Append((XmlAttribute)attrib.CloneNode(true));
                            removeAttributes.Add(attrib);
                        }
                        else if (rootPrefix == attrib.Name.Substring(6))
                        {
                            removeAttributes.Add(attrib);
                        }
                    }
                }
                foreach (var removeAttribute in removeAttributes)
                {
                    element.Attributes.Remove(removeAttribute);
                }
                //end remove

                XamlParser parser = new XamlParser();
                parser.settings = settings;
                parser.document = root.OwnerDocument;
                var xamlObject = parser.ParseObject(element as XmlElement);
                if (xamlObject != null)
                {
                    return(xamlObject);
                }
            }
            return(null);
        }
コード例 #4
0
ファイル: XamlParser.cs プロジェクト: lvv83/SharpDevelop
		/// <summary>
		/// Method use to parse a piece of Xaml.
		/// </summary>
		/// <param name="root">The Root XamlObject of the current document.</param>
		/// <param name="xaml">The Xaml being parsed.</param>
		/// <param name="settings">Parser settings used by <see cref="XamlParser"/>.</param>
		/// <param name="parentObject">Parent Object, where the Parsed snippet will be inserted (Needed for Example for Bindings).</param>
		/// <returns>Returns the XamlObject of the parsed <paramref name="xaml"/>.</returns>
		public static XamlObject ParseSnippet(XamlObject root, string xaml, XamlParserSettings settings, XamlObject parentObject)
		{
			XmlTextReader reader = new XmlTextReader(new StringReader(xaml));
			var element = root.OwnerDocument.XmlDocument.ReadNode(reader);
			
			if (element != null) {
				XmlAttribute xmlnsAttribute=null;
				foreach (XmlAttribute attrib in element.Attributes) {
					if (attrib.Name == "xmlns")
						xmlnsAttribute = attrib;
				}
				if(xmlnsAttribute!=null)
					element.Attributes.Remove(xmlnsAttribute);
				
				XamlParser parser = new XamlParser();
				parser.settings = settings;
				parser.errorSink = (IXamlErrorSink)settings.ServiceProvider.GetService(typeof(IXamlErrorSink));
				parser.document = root.OwnerDocument;
				parser.currentXamlObject = parentObject;
				var xamlObject = parser.ParseObject(element as XmlElement);

				RemoveRootNamespacesFromNodeAndChildNodes(root, element);

				if (xamlObject != null)
					return xamlObject;
			}
			return null;
		}
コード例 #5
0
ファイル: XamlParser.cs プロジェクト: lvv83/SharpDevelop
		internal static XamlDocument Parse(XmlDocument document, XamlParserSettings settings)
		{
			if (document == null)
				throw new ArgumentNullException("document");
			if (settings == null)
				throw new ArgumentNullException("settings");
			XamlParser p = new XamlParser();
			p.settings = settings;
			p.errorSink = (IXamlErrorSink)settings.ServiceProvider.GetService(typeof(IXamlErrorSink));
			p.document = new XamlDocument(document, settings);
			
			try {
				var root = p.ParseObject(document.DocumentElement);
				p.document.ParseComplete(root);
			} catch (Exception x) {
				p.ReportException(x, p.currentParsedNode);
			}

			return p.document;
		}
コード例 #6
0
ファイル: XamlParser.cs プロジェクト: Bombadil77/SharpDevelop
		/// <summary>
		/// Method use to parse a piece of Xaml.
		/// </summary>
		/// <param name="root">The Root XamlObject of the current document.</param>
		/// <param name="xaml">The Xaml being parsed.</param>
		/// <param name="settings">Parser settings used by <see cref="XamlParser"/>.</param>
		/// <returns>Returns the XamlObject of the parsed <paramref name="xaml"/>.</returns>
		public static XamlObject ParseSnippet(XamlObject root, string xaml, XamlParserSettings settings)
		{
			XmlTextReader reader = new XmlTextReader(new StringReader(xaml));
			var element = root.OwnerDocument.XmlDocument.ReadNode(reader);
			
			if (element != null) {
				XmlAttribute xmlnsAttribute=null;
				foreach (XmlAttribute attrib in element.Attributes) {
					if (attrib.Name == "xmlns")
						xmlnsAttribute = attrib;
				}
				if(xmlnsAttribute!=null)
					element.Attributes.Remove(xmlnsAttribute);

				XamlParser parser = new XamlParser();
				parser.settings = settings;
				parser.document = root.OwnerDocument;
				var xamlObject = parser.ParseObject(element as XmlElement);
				if (xamlObject != null)
					return xamlObject;
			}
			return null;
		}
コード例 #7
0
ファイル: XamlParser.cs プロジェクト: asiazhang/SharpDevelop
		/// <summary>
		/// Method use to parse a piece of Xaml.
		/// </summary>
		/// <param name="root">The Root XamlObject of the current document.</param>
		/// <param name="xaml">The Xaml being parsed.</param>
		/// <param name="settings">Parser settings used by <see cref="XamlParser"/>.</param>
		/// <returns>Returns the XamlObject of the parsed <paramref name="xaml"/>.</returns>
		public static XamlObject ParseSnippet(XamlObject root, string xaml, XamlParserSettings settings)
		{
			XmlTextReader reader = new XmlTextReader(new StringReader(xaml));
			var element = root.OwnerDocument.XmlDocument.ReadNode(reader);
			
			if (element != null) {
				XmlAttribute xmlnsAttribute=null;
				foreach (XmlAttribute attrib in element.Attributes) {
					if (attrib.Name == "xmlns")
						xmlnsAttribute = attrib;
				}
				if(xmlnsAttribute!=null)
					element.Attributes.Remove(xmlnsAttribute);

				//Remove namespace Attributes defined in the Xaml Root from the Pasted Snippet!
				List<XmlAttribute> removeAttributes = new List<XmlAttribute>();
				foreach (XmlAttribute attrib in element.Attributes) {
					if (attrib.Name.StartsWith("xmlns:")) {
						var rootPrefix = root.OwnerDocument.GetPrefixForNamespace(attrib.Value);
						if (rootPrefix == null) {
							//todo: check if we can add to root, (maybe same ns exists)
							root.OwnerDocument.XmlDocument.Attributes.Append((XmlAttribute)attrib.CloneNode(true));
							removeAttributes.Add(attrib);
						} else if (rootPrefix == attrib.Name.Substring(6)) {
							removeAttributes.Add(attrib);
						}
					}
				}
				foreach (var removeAttribute in removeAttributes) {
					element.Attributes.Remove(removeAttribute);
				}
				//end remove
				
				XamlParser parser = new XamlParser();
				parser.settings = settings;
				parser.document = root.OwnerDocument;
				var xamlObject = parser.ParseObject(element as XmlElement);
				if (xamlObject != null)
					return xamlObject;
			}
			return null;
		}