示例#1
0
 string GetXmlString(SaveOptions o)
 {
     using (StringWriter sw = new StringWriter(CultureInfo.InvariantCulture))
     {
         XmlWriterSettings ws = new XmlWriterSettings();
         ws.OmitXmlDeclaration = true;
         if ((o & SaveOptions.DisableFormatting) == 0)
         {
             ws.Indent = true;
         }
         if ((o & SaveOptions.OmitDuplicateNamespaces) != 0)
         {
             ws.NamespaceHandling |= NamespaceHandling.OmitDuplicates;
         }
         if (this is XText)
         {
             ws.ConformanceLevel = ConformanceLevel.Fragment;
         }
         using (XmlWriter w = XmlWriter.Create(sw, ws))
         {
             XDocument n = this as XDocument;
             if (n != null)
             {
                 n.WriteContentTo(w);
             }
             else
             {
                 WriteTo(w);
             }
         }
         return(sw.ToString());
     }
 }
示例#2
0
 private string GetXmlString(SaveOptions o)
 {
     using (StringWriter writer = new StringWriter(CultureInfo.InvariantCulture))
     {
         XmlWriterSettings settings = new XmlWriterSettings {
             OmitXmlDeclaration = true
         };
         if ((o & SaveOptions.DisableFormatting) == SaveOptions.None)
         {
             settings.Indent = true;
         }
         if ((o & SaveOptions.OmitDuplicateNamespaces) != SaveOptions.None)
         {
             settings.NamespaceHandling |= NamespaceHandling.OmitDuplicates;
         }
         if (this is XText)
         {
             settings.ConformanceLevel = ConformanceLevel.Fragment;
         }
         using (XmlWriter writer2 = XmlWriter.Create(writer, settings))
         {
             XDocument document = this as XDocument;
             if (document != null)
             {
                 document.WriteContentTo(writer2);
             }
             else
             {
                 this.WriteTo(writer2);
             }
         }
         return(writer.ToString());
     }
 }