示例#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();
                }
            }
        }
示例#2
0
        internal void WritePreservedAttributes(XmlAttributePreservingWriter writer, XmlAttributeCollection attributes)
        {
            string newLineString = null;

            if (this.attributeNewLineString != null)
            {
                newLineString = writer.SetAttributeNewLineString(this.attributeNewLineString);
            }
            try
            {
                foreach (string str2 in this.orderedAttributes)
                {
                    XmlAttribute attribute = attributes[str2];
                    if (attribute != null)
                    {
                        if (this.leadingSpaces.ContainsKey(str2))
                        {
                            writer.WriteAttributeWhitespace(this.leadingSpaces[str2]);
                        }
                        attribute.WriteTo(writer);
                    }
                }
                if (this.leadingSpaces.ContainsKey(string.Empty))
                {
                    writer.WriteAttributeTrailingWhitespace(this.leadingSpaces[string.Empty]);
                }
            }
            finally
            {
                if (newLineString != null)
                {
                    writer.SetAttributeNewLineString(newLineString);
                }
            }
        }
示例#3
0
        public override void Save(string filename)
        {
            XmlWriter xmlWriter = null;

            using (Stream file = File.Create(filename))
            {
                try
                {
                    if (PreserveWhitespace)
                    {
                        XmlFormatter.Format(this);
                        xmlWriter = new XmlAttributePreservingWriter(file, TextEncoding);
                    }
                    else
                    {
                        XmlTextWriter textWriter = new XmlTextWriter(file, TextEncoding);
                        textWriter.Formatting = Formatting.Indented;
                        xmlWriter             = textWriter;
                    }
                    WriteTo(xmlWriter);
                }
                finally
                {
                    if (xmlWriter != null)
                    {
                        xmlWriter.Flush();
                        xmlWriter.Close();
                    }
                }
            }
        }
示例#4
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();
                }
            }
        }
示例#5
0
        public void Save(string filename)
        {
            XmlWriter  xmlWriter = null;
            FileStream stream    = null;

            try
            {
                if (PreserveWhitespace)
                {
                    XmlFormatter.Format(this);
                    stream    = File.OpenWrite(filename);
                    xmlWriter = new XmlAttributePreservingWriter(stream, TextEncoding);
                }
                else
                {
                    stream = File.OpenWrite(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();
                }
            }
        }
示例#6
0
            public override void WriteTo(XmlWriter w)
            {
                string prefix = this.Prefix;

                if (!string.IsNullOrEmpty(this.NamespaceURI))
                {
                    prefix = w.LookupPrefix(this.NamespaceURI);
                    if (prefix == null)
                    {
                        prefix = this.Prefix;
                    }
                }
                w.WriteStartElement(prefix, this.LocalName, this.NamespaceURI);
                XmlAttributePreservingWriter preservingWriter = w as XmlAttributePreservingWriter;

                if ((preservingWriter != null) && (this.preservationDict != null))
                {
                    this.WritePreservedAttributesTo(preservingWriter);
                }
                else
                {
                    this.WriteAttributesTo(w);
                }
                if (base.IsEmpty)
                {
                    w.WriteEndElement();
                }
                else
                {
                    this.WriteContentTo(w);
                    w.WriteFullEndElement();
                }
            }
示例#7
0
        public override void Save(string filename)
        {
            XmlWriter w = null;

            try
            {
                if (base.PreserveWhitespace)
                {
                    XmlFormatter.Format(this);
                    w = new XmlAttributePreservingWriter(filename, this.TextEncoding);
                }
                else
                {
                    XmlTextWriter writer2 = new XmlTextWriter(filename, this.TextEncoding)
                    {
                        Formatting = Formatting.Indented
                    };
                    w = writer2;
                }
                this.WriteTo(w);
            }
            finally
            {
                if (w != null)
                {
                    w.Flush();
                    w.Close();
                }
            }
        }
示例#8
0
        public override void Save(Stream w)
        {
            XmlWriter writer = null;

            try
            {
                if (base.PreserveWhitespace)
                {
                    XmlFormatter.Format(this);
                    writer = new XmlAttributePreservingWriter(w, this.TextEncoding);
                }
                else
                {
                    XmlTextWriter writer2 = new XmlTextWriter(w, this.TextEncoding)
                    {
                        Formatting = Formatting.Indented
                    };
                    writer = writer2;
                }
                this.WriteTo(writer);
            }
            finally
            {
                if (writer != null)
                {
                    writer.Flush();
                }
            }
        }
示例#9
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);
                }
            }
        }
示例#11
0
 private void WritePreservedAttributesTo(XmlAttributePreservingWriter preservingWriter)
 {
     preservationDict.WritePreservedAttributes(preservingWriter, Attributes);
 }
 private void WritePreservedAttributesTo(XmlAttributePreservingWriter preservingWriter) {
     preservationDict.WritePreservedAttributes(preservingWriter, Attributes);
 }
 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();
         }
     }
 }
        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);
                }
            }
        }