當前位置: 首頁>>代碼示例>>C#>>正文


C# XElement.Save方法代碼示例

本文整理匯總了C#中System.Xml.Linq.XElement.Save方法的典型用法代碼示例。如果您正苦於以下問題:C# XElement.Save方法的具體用法?C# XElement.Save怎麽用?C# XElement.Save使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在System.Xml.Linq.XElement的用法示例。


在下文中一共展示了XElement.Save方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: Trans

 private void Trans(XElement serializedExpression)
 {
     serializedExpression.Save("beforeTransit.xml");
     Console.WriteLine("beforeTransit:");
     Console.WriteLine(serializedExpression.ToString());
     Transit(serializedExpression);
     Console.WriteLine("afterTransit:");
     Console.WriteLine(serializedExpression.ToString());
     serializedExpression.Save("afterTransit.xml");
 }
開發者ID:fr4nky80,項目名稱:LearnCSharp,代碼行數:10,代碼來源:ExpressionSerializationTest.cs

示例2: SaveXml

 /// <summary>
 /// 保存xml對象至文件
 /// </summary>
 /// <param name="xe">要保存的內容</param>
 /// <param name="xmlName">保存的文件名(不含擴展名)</param>
 /// <param name="isFullXmlName">True=程序內配置路徑地址,隻含文件名(不含擴展名)====False=文件絕對地址</param>
 public void SaveXml(XElement xe, string xmlName, bool isFullXmlName)
 {
     if (isFullXmlName)
     {
         CreatNewDirTry();
         xe.Save(GetXMLFileFullName(xmlName));
     }
     else
     {
         xe.Save(GetXMLFileFullName(xmlName));
     }
 }
開發者ID:a44281071,項目名稱:osu--Helper,代碼行數:18,代碼來源:File_Helper.cs

示例3: Export

 public static void Export(List<Dictionary<string, string>> data, string savepath, string format)
 {
     if (format == "JSON")
     {
         string json = JsonConvert.SerializeObject(data, Formatting.Indented);
         File.WriteAllText(savepath, json);
     }
     else if (format == "XML")
     {
         XElement root = new XElement("Items");
         foreach (var item in data)
         {
             XElement itemEle = new XElement("Item");
             itemEle.Add(item.Select(kv => new XElement(kv.Key, kv.Value)));
             root.Add(itemEle);
         }
         root.Save(savepath);
     }
     else if (format == "CSV")
     {
         string res = "";
         foreach (var item in data)
         {
             res += String.Join(", ",item.Select(kv => string.Format("\"{0}\"", kv.Value)))+"\n";
         }
         File.WriteAllText(savepath, res);
     }
 }
開發者ID:Corv,項目名稱:D3Bit,代碼行數:28,代碼來源:Exporter.cs

示例4: Main

 static void Main()
 {
     DirectoryInfo directory = new DirectoryInfo(@"../../../../02.XMLProcessingIn.NET");
     XElement dirXml = new XElement("directory");
     dirXml.Add(TraverseDirectory(directory));
     dirXml.Save("../../../dirsX.xml");
 }
開發者ID:zvet80,項目名稱:TelerikAcademyHomework,代碼行數:7,代碼來源:TraverseDirX.cs

示例5: Generate

        public static void Generate()
        {
            using (var db = new SalesContext())
            {
                var sales = new XElement("sales");

                foreach (var supermarket in db.Supermarkets)
                {
                    var sale = new XElement("sale");
                    sale.SetAttributeValue("vendor", supermarket.Name);

                    var records = db.Records
                        .Where(x => x.Supermarket.Id == supermarket.Id)
                        .GroupBy(x => x.Date)
                        .OrderBy(x => x.Key)
                        .Select(x => new { Date = x.Key, Sum = x.Sum(y => y.Quantity * y.UnitPrice) });

                    foreach (var record in records)
                    {
                        var summary = new XElement("summary");

                        summary.SetAttributeValue("date", record.Date.ToShortDateString());
                        summary.SetAttributeValue("total-sum", record.Sum.ToString("00"));

                        sale.Add(summary);
                    }

                    sales.Add(sale);
                }

                sales.Save(FilePath);
                //Console.WriteLine(File.ReadAllText(FilePath));
            }
        }
開發者ID:aleks-todorov,項目名稱:HomeWorks,代碼行數:34,代碼來源:SalesReportsByVendors.cs

示例6: Main

        static void Main()
        {
            // Creating person.txt
            string textFilePath = "../../person.txt";
            StreamWriter writer = new StreamWriter(textFilePath);

            using (writer)
            {
                writer.WriteLine("Иван Иванов");
                writer.WriteLine("Перущица, ул.'Освобождение', №1");
                writer.WriteLine("+359888123456");
            }

            StreamReader reader = new StreamReader(textFilePath);

            using (reader)
            {
                var person = new
                {
                    Name = reader.ReadLine(),
                    Address = reader.ReadLine(),
                    Phone = reader.ReadLine()
                };

                XElement personXElement = new XElement("Person",
                    new XElement("Name", person.Name),
                    new XElement("Address", person.Address),
                    new XElement("Phone", person.Phone));

                personXElement.Save("../../person.xml");
            }
        }
開發者ID:MarinMarinov,項目名稱:Databases,代碼行數:32,代碼來源:Program.cs

示例7: CreateXmlFile

        // creates folder, .xml file, and inserts data
        public static bool CreateXmlFile(string root, XElement fileSystemTree)
        {


            string pathString = System.IO.Path.Combine(root, "XMLFolder");

            System.IO.Directory.CreateDirectory(pathString);

            string fileName = "XMLFile.xml";
            // Using Combine to add the file name to the path.
            pathString = System.IO.Path.Combine(pathString, fileName);


            if (!System.IO.File.Exists(pathString))
            {
                using (System.IO.FileStream fs = System.IO.File.Create(pathString))
                {

                    fileSystemTree.Save(fs);
                    return true;
                }
            }
            else
            {
                return false;
            }


        }
開發者ID:dusanpajic,項目名稱:XMLFileTree,代碼行數:30,代碼來源:Execute.cs

示例8: WriteToStreamAsync

        public override Task WriteToStreamAsync(Type type, object value,
            Stream writeStream, System.Net.Http.HttpContent content,
            System.Net.TransportContext transportContext)
        {
            return Task.Factory.StartNew(() =>
            {
                if (typeof(IEnumerable<IData>).IsAssignableFrom(type))
                {
                    Type elementType = type.GetGenericArguments().First();

                    var resultXElement = new XElement("Data");

                    foreach (var element in (value as IEnumerable))
                    {
                        resultXElement.Add(GetXNode(elementType.Name, element).Root);
                    }

                    resultXElement.Save(writeStream);
                    return;
                }

                XDocument xNode = GetXNode(type.Name, value);

                xNode.Save(writeStream);
            });
        }
開發者ID:portal7,項目名稱:CompositeC1-WebAPI_Demo,代碼行數:26,代碼來源:CustomIDataXmlFormatter.cs

示例9: backupXML

        protected override void backupXML(string plikXml,string serwis,string typ)
        {
            if (numKolekcja.Count > 0)
                    {
                    var xmlFile = new XElement(typ.Replace(' ', '_'), new XAttribute("Data", DateTime.Now.ToString("dd-MM-yyyy")));

                    foreach (var elem in numKolekcja)
                        {
                        var x = new XElement("Row",
                            new XAttribute("Nazwa", elem.Nazwa),
                            new XAttribute("Symbol", elem.Symbol),
                            new XAttribute("Data", elem.Data),
                            new XAttribute("Kurs", elem.Kurs),
                            new XAttribute("MaxMin", elem.MaxMin),
                            new XAttribute("Zmiana", elem.Zmiana),
                            new XAttribute("ZmianaProc", elem.ZmianaProc),
                            new XAttribute("Otwarcie", elem.Otwarcie),
                            new XAttribute("Odniesienie", elem.Odniesienie),
                            new XAttribute("Wolumen", elem.Wolumen),
                            new XAttribute("Obrot", elem.Obrot),
                            new XAttribute("Transakcje", elem.Transakcje));

                        xmlFile.Add(x);
                        }

                    xmlFile.Save(plikXml);
                    Loger.dodajDoLogaInfo(serwis + typ + messages.xmlOutOK);
                    }
                else
                    Loger.dodajDoLogaError(serwis + typ + messages.xmlOutFail);
        }
開發者ID:marazmista,項目名稱:wigo,代碼行數:31,代碼來源:klasyakcjowe.cs

示例10: ValidateSave

        public void ValidateSave()
        {
            WorldEntity world = createTestWorld();

            XElement xElement = WorldTransformer.Instance.ToXElement(world, TransformerSettings.WorldNamespace + "World");

            xElement.Save("unittestsave.xml", SaveOptions.OmitDuplicateNamespaces);

            XmlSchemaSet schemaSet = new XmlSchemaSet();

            schemaSet.Add(null, "WorldSchema1.xsd");

            XDocument xDocument = new XDocument(xElement);
            xDocument.AddAnnotation(SaveOptions.OmitDuplicateNamespaces);
            xDocument.Save("unittest2.xml", SaveOptions.OmitDuplicateNamespaces);

            XElement x1 = new XElement(TransformerSettings.WorldNamespace + "Outer");
            x1.Add(new XElement(TransformerSettings.WorldNamespace + "Inner"));
            x1.Save("unittest3.xml", SaveOptions.OmitDuplicateNamespaces);
            string val = "";
            xDocument.Validate(schemaSet, (o, vea) => {
                val += o.GetType().Name + "\n";
                val += vea.Message + "\n";
            }, true);

            Assert.AreEqual("", val);
        }
開發者ID:neaket,項目名稱:Dragonfly,代碼行數:27,代碼來源:WorldTests.cs

示例11: ExitSave

 public void ExitSave()
 {
     XElement xRoot = new XElement("ChosenPath");
     XAttribute xPath = new XAttribute("Path", filepath);
     xRoot.Add(xPath);
     xRoot.Save("Config.xml");
 }
開發者ID:Jon-Stumpfel,項目名稱:league-of-champion-craft,代碼行數:7,代碼來源:ParticleEditor.cs

示例12: Main

        static void Main()
        {
            //Write a program to traverse given directory and write to a XML file its contents together with all subdirectories and files.
            //Use tags <file> and <dir> with attributes. Use XDocument, XElement and XAttribute.
            XElement directoryXml =
                new XElement("root-dir",
                    new XAttribute("path", "C:/Example"),
                    new XElement("dir",
                        new XAttribute("name", "docs"),
                        new XElement("file",
                            new XAttribute("name", "tutorial.pdf")),
                        new XElement("file",
                            new XAttribute("name", "TODO.txt")),
                        new XElement("file",
                            new XAttribute("name", "Presentation.pptx"))),
                    new XElement("dir",
                        new XAttribute("name", "photos"),
                        new XElement("file",
                            new XAttribute("name", "friends.jpg")),
                        new XElement("file",
                            new XAttribute("name", "the_cake.jpg"))
                        )
                    );

            Console.WriteLine(directoryXml);
            directoryXml.Save("../../../directoryXml.xml");
        }
開發者ID:dpetrova,項目名稱:Database-Applications,代碼行數:27,代碼來源:Program.cs

示例13: SetUserRoles

        public static void SetUserRoles(params UserRole[] roles)
        {
            var xml = new XElement("Roles",
                                   roles.Select(role => new XElement("Role", role)));

            xml.Save(TestUserRolesFilePath);
        }
開發者ID:Gwayaboy,項目名稱:iDeal,代碼行數:7,代碼來源:FileBasedTestSecurityHelper.cs

示例14: ConvertXElementToString

        private static string ConvertXElementToString(XElement xElement)
        {
            if (xElement == null)
            {
                throw new ArgumentNullException("xElement");
            }

            // Convert the xml to a string.
            string xmlResult;
            using (var memoryStream = new MemoryStream())
            {
                using (var writer = new StreamWriter(memoryStream, Encoding.UTF8))
                {
                    xElement.Save(writer);
                }

                xmlResult = Encoding.UTF8.GetString(memoryStream.ToArray());
            }

            if (!string.IsNullOrWhiteSpace(xmlResult) &&
                xmlResult.StartsWith(ByteOrderMarkUtf8))
            {
                xmlResult = xmlResult.Remove(0, ByteOrderMarkUtf8.Length);
            }

            return xmlResult;
        }
開發者ID:baywet,項目名稱:SimpleSitemap,代碼行數:27,代碼來源:SitemapService.cs

示例15: Main

 public static void Main()
 {
     XElement directories = new XElement("directories");
     DirectoiesTravers("../../", directories);
     Console.WriteLine("New file is created with name - Directoies.xml");
     directories.Save("../../Directoies.xml");
 }
開發者ID:quela,項目名稱:myprojects,代碼行數:7,代碼來源:TraverseFileSystemLinq.cs


注:本文中的System.Xml.Linq.XElement.Save方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。