Inheritance: System.Xml.XmlTextWriter
        public override void Transform(Engine engine, Package package)
        {
            this.Package = package;
            this.Engine = engine;
            XmlSerializer serializer;

            Dynamic.Component component;
            bool hasOutput = HasPackageValue(package, "Output");
            if (hasOutput)
            {
                GeneralUtils.TimedLog("start retrieving previous Output from package");
                String inputValue = package.GetValue("Output");
                GeneralUtils.TimedLog("start deserializing");
                TextReader tr = new StringReader(inputValue);
                GeneralUtils.TimedLog("start creating serializer");
                serializer = new XmlSerializerFactory().CreateSerializer(typeof(Dynamic.Component));
                GeneralUtils.TimedLog("finished creating serializer");
                component = (Dynamic.Component)serializer.Deserialize(tr);
                GeneralUtils.TimedLog("finished deserializing from package");
            }
            else
            {
                GeneralUtils.ResetLogTimer();
                GeneralUtils.TimedLog("Could not find 'Output' in the package");
                GeneralUtils.TimedLog("Start creating dynamic component from current component in the package");
                GeneralUtils.TimedLog("start creating serializer");
                serializer = new XmlSerializerFactory().CreateSerializer(typeof(Dynamic.Component));
                GeneralUtils.TimedLog("finished creating serializer");
                component = GetDynamicComponent(manager);
                GeneralUtils.TimedLog("Finished creating dynamic component with title " + component.Title);
            }

            try
            {
                GeneralUtils.TimedLog("starting transformComponent");
                TransformComponent(component);
                GeneralUtils.TimedLog("finished transformComponent");
            }
            catch (StopChainException)
            {
                GeneralUtils.TimedLog("caught stopchainexception, will not write current component back to the package");
                return;
            }
            var sw = new StringWriter();
            var ms = new MemoryStream();
            XmlWriter writer = new XmlTextWriterFormattedNoDeclaration(ms, Encoding.UTF8);
            string outputValue;
            //Create our own namespaces for the output
            var ns = new XmlSerializerNamespaces();

            //Add an empty namespace and empty value
            ns.Add("", "");

            serializer.Serialize(writer, component, ns);
            outputValue = Encoding.UTF8.GetString(ms.ToArray());

            // for some reason, the .NET serializer leaves an invalid character at the start of the string
            // we will remove everything up to the first < so that the XML can be deserialized later!
            Regex re = new Regex("^[^<]+");
            outputValue = re.Replace(outputValue, "");

            if (hasOutput)
            {
                Item outputItem = package.GetByName("Output");
                package.Remove(outputItem);
                outputItem.SetAsString(outputValue);
                package.PushItem("Output", outputItem);
            }
            else
            {
                package.PushItem(Package.OutputName, package.CreateStringItem(ContentType.Text, outputValue));
            }

            GeneralUtils.TimedLog("finished Transform");
        }
        public override void Transform(Engine engine, Package package)
        {
            this.Package = package;
            this.Engine  = engine;
            XmlSerializer serializer;

            Dynamic.Component component;
            bool hasOutput = HasPackageValue(package, "Output");

            if (hasOutput)
            {
                GeneralUtils.TimedLog("start retrieving previous Output from package");
                String inputValue = package.GetValue("Output");
                GeneralUtils.TimedLog("start deserializing");
                TextReader tr = new StringReader(inputValue);
                GeneralUtils.TimedLog("start creating serializer");
                serializer = new XmlSerializerFactory().CreateSerializer(typeof(Dynamic.Component));
                GeneralUtils.TimedLog("finished creating serializer");
                component = (Dynamic.Component)serializer.Deserialize(tr);
                GeneralUtils.TimedLog("finished deserializing from package");
            }
            else
            {
                GeneralUtils.ResetLogTimer();
                GeneralUtils.TimedLog("Could not find 'Output' in the package");
                GeneralUtils.TimedLog("Start creating dynamic component from current component in the package");
                GeneralUtils.TimedLog("start creating serializer");
                serializer = new XmlSerializerFactory().CreateSerializer(typeof(Dynamic.Component));
                GeneralUtils.TimedLog("finished creating serializer");
                component = GetDynamicComponent(manager);
                GeneralUtils.TimedLog("Finished creating dynamic component with title " + component.Title);
            }

            try
            {
                GeneralUtils.TimedLog("starting transformComponent");
                TransformComponent(component);
                GeneralUtils.TimedLog("finished transformComponent");
            }
            catch (StopChainException)
            {
                GeneralUtils.TimedLog("caught stopchainexception, will not write current component back to the package");
                return;
            }
            var       sw     = new StringWriter();
            var       ms     = new MemoryStream();
            XmlWriter writer = new XmlTextWriterFormattedNoDeclaration(ms, Encoding.UTF8);
            string    outputValue;
            //Create our own namespaces for the output
            var ns = new XmlSerializerNamespaces();

            //Add an empty namespace and empty value
            ns.Add("", "");

            serializer.Serialize(writer, component, ns);
            outputValue = Encoding.UTF8.GetString(ms.ToArray());

            // for some reason, the .NET serializer leaves an invalid character at the start of the string
            // we will remove everything up to the first < so that the XML can be deserialized later!
            Regex re = new Regex("^[^<]+");

            outputValue = re.Replace(outputValue, "");

            if (hasOutput)
            {
                Item outputItem = package.GetByName("Output");
                package.Remove(outputItem);
                outputItem.SetAsString(outputValue);
                package.PushItem("Output", outputItem);
            }
            else
            {
                package.PushItem(Package.OutputName, package.CreateStringItem(ContentType.Text, outputValue));
            }

            GeneralUtils.TimedLog("finished Transform");
        }