Ejemplo n.º 1
0
        public XmlNode Process(IResource resource)
        {
            try
            {
                using (resource)
                {
                    var doc = new XmlDocument();
                    using (var stream = resource.GetStreamReader())
                    {
                        doc.Load(stream);
                    }

                    engine.PushResource(resource);

                    var element = Process(doc.DocumentElement);

                    engine.PopResource();

                    return(element);
                }
            }
            catch (ConfigurationProcessingException)
            {
                throw;
            }
            catch (Exception ex)
            {
                var message = String.Format("Error processing node resource {0}", resource);

                throw new ConfigurationProcessingException(message, ex);
            }
        }
Ejemplo n.º 2
0
        public XmlNode ProcessInclude(XmlElement element, String includeUri, IXmlProcessorEngine engine)
        {
            XmlDocumentFragment frag = null;

            if (includeUri == null)
            {
                throw new ConfigurationProcessingException(
                          String.Format("Found an include node without an 'uri' attribute: {0}", element.BaseURI));
            }

            var uriList = includeUri.Split(',');

            frag = CreateFragment(element);

            foreach (var uri in uriList)
            {
                using (var resource = engine.GetResource(uri))
                {
                    var doc = new XmlDocument();

                    try
                    {
                        using (var stream = resource.GetStreamReader())
                        {
                            doc.Load(stream);
                        }
                    }
                    catch (Exception ex)
                    {
                        throw new ConfigurationProcessingException(
                                  String.Format("Error processing include node: {0}", includeUri), ex);
                    }

                    engine.PushResource(resource);

                    engine.DispatchProcessAll(new DefaultXmlProcessorNodeList(doc.DocumentElement));

                    engine.PopResource();

                    if (element.GetAttribute("preserve-wrapper") == "yes")
                    {
                        AppendChild(frag, doc.DocumentElement);
                    }
                    else
                    {
                        AppendChild(frag, doc.DocumentElement.ChildNodes);
                    }
                }
            }

            return(frag);
        }
		public XmlNode ProcessInclude(XmlElement element, String includeUri, IXmlProcessorEngine engine)
		{
			XmlDocumentFragment frag = null;

			if (includeUri == null)
			{
				throw new ConfigurationProcessingException(
					String.Format("Found an include node without an 'uri' attribute: {0}", element.BaseURI));
			}

			String[] uriList = includeUri.Split(',');
			frag = CreateFragment(element);

			foreach(String uri in uriList)
			{
				using(IResource resource = engine.GetResource(uri))
				{
					XmlDocument doc = new XmlDocument();

					try
					{
						using (var stream = resource.GetStreamReader())
						{
							doc.Load(stream);
						}
					}
					catch(Exception ex)
					{
						throw new ConfigurationProcessingException(
							String.Format("Error processing include node: {0}", includeUri), ex);
					}

					engine.PushResource(resource);

					engine.DispatchProcessAll(new DefaultXmlProcessorNodeList(doc.DocumentElement));

					engine.PopResource();

					if (element.GetAttribute("preserve-wrapper") == "yes")
					{
						AppendChild(frag, doc.DocumentElement);
					}
					else
					{
						AppendChild(frag, doc.DocumentElement.ChildNodes);
					}
				}
			}

			return frag;
		}