Ejemplo n.º 1
0
        public override void Save(Stream w)
        {
            XmlWriter xmlWriter = null;

            try {
                if (PreserveWhitespace)
                {
                    XmlFormatter.Format(this);
                    xmlWriter = new XmlAttributePreservingWriter(w, TextEncoding);
                }
                else
                {
                    XmlTextWriter textWriter = new XmlTextWriter(w, TextEncoding);
                    textWriter.Formatting = Formatting.Indented;
                    xmlWriter             = textWriter;
                }
                WriteTo(xmlWriter);
            }
            finally {
                if (xmlWriter != null)
                {
                    xmlWriter.Flush();
                }
            }
        }
Ejemplo n.º 2
0
        public override void Save(TextWriter writer)
        {
            XmlWriter xmlWriter = null;

            try
            {
                if (PreserveWhitespace)
                {
                    XmlFormatter.Format(this);
                    xmlWriter = new XmlAttributePreservingWriter(writer);
                }
                else
                {
                    xmlWriter = XmlWriter.Create(writer);
                    xmlWriter.Settings.Encoding = TextEncoding;
                    xmlWriter.Settings.Indent   = true;
                }
                WriteTo(xmlWriter);
            }
            finally
            {
                if (xmlWriter != null)
                {
                    xmlWriter.Flush();
                    xmlWriter.Dispose();
                }
            }
        }
Ejemplo n.º 3
0
        public void Save(string filename)
        {
            XmlWriter  xmlWriter = null;
            FileStream stream    = null;

            try{
                if (PreserveWhitespace)
                {
                    XmlFormatter.Format(this);
                    stream    = File.Create(filename);
                    xmlWriter = new XmlAttributePreservingWriter(stream, TextEncoding);
                }
                else
                {
                    stream = File.Create(filename);
                    XmlTextWriter textWriter = new XmlTextWriter(stream, TextEncoding);
                    textWriter.Formatting = Formatting.Indented;
                    xmlWriter             = textWriter;
                }
                WriteTo(xmlWriter);
            }
            finally {
                if (xmlWriter != null)
                {
                    xmlWriter.Flush();
                    xmlWriter.Dispose();
                }
                if (stream != null)
                {
                    stream.Dispose();
                }
            }
        }
Ejemplo n.º 4
0
            public override void WriteTo(XmlWriter w)
            {
                string prefix = Prefix;

                if (!String.IsNullOrEmpty(NamespaceURI))
                {
                    prefix = w.LookupPrefix(NamespaceURI);
                    if (prefix == null)
                    {
                        prefix = Prefix;
                    }
                }

                w.WriteStartElement(prefix, LocalName, NamespaceURI);

                if (HasAttributes)
                {
                    XmlAttributePreservingWriter preservingWriter = w as XmlAttributePreservingWriter;
                    if (preservingWriter == null || preservationDict == null)
                    {
                        WriteAttributesTo(w);
                    }
                    else
                    {
                        WritePreservedAttributesTo(preservingWriter);
                    }
                }

                if (IsEmpty)
                {
                    w.WriteEndElement();
                }
                else
                {
                    WriteContentTo(w);
                    w.WriteFullEndElement();
                }
            }
        internal void WritePreservedAttributes(XmlAttributePreservingWriter writer, XmlAttributeCollection attributes)
        {
            string oldNewLineString = null;

            if (attributeNewLineString != null)
            {
                oldNewLineString = writer.SetAttributeNewLineString(attributeNewLineString);
            }

            try {
                foreach (string attributeName in orderedAttributes)
                {
                    XmlAttribute attr = attributes[attributeName];
                    if (attr != null)
                    {
                        if (leadingSpaces.ContainsKey(attributeName))
                        {
                            writer.WriteAttributeWhitespace(leadingSpaces[attributeName]);
                        }

                        attr.WriteTo(writer);
                    }
                }

                if (leadingSpaces.ContainsKey(String.Empty))
                {
                    writer.WriteAttributeTrailingWhitespace(leadingSpaces[String.Empty]);
                }
            }
            finally {
                if (oldNewLineString != null)
                {
                    writer.SetAttributeNewLineString(oldNewLineString);
                }
            }
        }
Ejemplo n.º 6
0
 private void WritePreservedAttributesTo(XmlAttributePreservingWriter preservingWriter)
 {
     preservationDict.WritePreservedAttributes(preservingWriter, Attributes);
 }