static void Main(string[] args) { XDocument document = new XDocument("This is the root element", new XElement("child1", new XElement("child1.1", new XElement("child1.1.1", "1.1.1"))), new XElement("child2", "2"), new XElement("child3", "3"), new XElement("child4", "4")); var element5 = new XElement("child4", "5"); document.Add(element5); Console.WriteLine(document); document.Remove(element5); Console.WriteLine(document); XDocument xdocument = new XMLBuilder("This is the root element") .AddElement("child1") .AddElement("child1.1") .AddElement("child1.1.1", "1.1.1") .Reset() .AddElement("child2", "2") .AddElement("child2", "3") .AddElement("child2", "4") .AddElement("child2", "5") .Root; Console.WriteLine(xdocument); }
/// <summary> /// Exports Data to XML and PDF File /// </summary> public void ExportData() { if (IsValidPOList == false) { MessageBox.Show(@"Export could not be completed due to the following possible causes: 1) Only online Spotify search results can be exported. 2) An offline export file that was imported cannot be exported again.", @"Warning", MessageBoxButtons.OK, MessageBoxIcon.Information, MessageBoxDefaultButton.Button1, MessageBoxOptions.DefaultDesktopOnly); return; } // 1. Build Export XML for import (leverage XMLBuilder) XMLBuilder xmlBuilder = new XMLBuilder(); SpotifySearchPO path = CompleteSpotifySearchList.FirstOrDefault(s => !string.IsNullOrEmpty(s.ImportExportLocationText)); DateTime date = DateTime.Now; string fileAppendDateFormat = $"{date.Year}{date.Day}{date.Month}{date.Hour}{date.Minute}"; string codedPathXml = @"\" + fileAppendDateFormat + "_SpotifySearchResults.xml"; string codedPathPdf = @"\" + fileAppendDateFormat + "_SpotifySearchResults.pdf"; if (path != null && !string.IsNullOrEmpty(path.ImportExportLocationText)) { xmlBuilder.CreateXMLFromSpotifySearchPOList(CompleteSpotifySearchList, path.ImportExportLocationText + codedPathXml); } else { // Place into my documents folder if user hasn't set an actual folder string myDocuments = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments); string myPath = myDocuments + @"\" + fileAppendDateFormat + "_SpotifySearchResults.xml"; xmlBuilder.CreateXMLFromSpotifySearchPOList(CompleteSpotifySearchList, myPath); } // 2. Build Export PDF for easy viewing (leverage PDFBuilder) PDFBuilder pdfBuilder = new PDFBuilder(); if (path != null && !string.IsNullOrEmpty(path.ImportExportLocationText)) { pdfBuilder.CreatePdfFromMainFrameDataPoList( CompleteSpotifySearchList, path.ImportExportLocationText + codedPathPdf); } else { // Place into my documents folder if user hasn't set an actual folder string myDocuments = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments); string myPath = myDocuments + @"\" + fileAppendDateFormat + "_SpotifySearchResults.pdf"; pdfBuilder.CreatePdfFromMainFrameDataPoList(CompleteSpotifySearchList, myPath); } }
static void Main(string[] args) { XMLBuilder xml = new XMLBuilder(); string xmlString = xml.AddHeader().AddTag("soap:Envelope").AddTag("soap:Body") .AddTag("id").AddContent("394").AddTag("id").AddComment("end of id tag") .AddTag("soap:Body").AddTag("soap:Envelope").Get(); Console.WriteLine(xmlString); string numbers = "893398"; string falseNumbers = "1234321"; Console.WriteLine(CheckOrder(numbers)); Console.WriteLine(CheckOrder(falseNumbers)); }
private String AllWorkshopsData() { XMLBuilder allWorkshopsXml = new XMLBuilder("workshops"); WorkshopRepository repository = this.WorkshopManager().GetWorkshopRepository(); List <String> ids = repository.GetIds(); foreach (String id in ids) { Workshop workshop = repository.GetWorkshop(id); allWorkshopsXml.AddBelowParent("workshop"); allWorkshopsXml.AddAttribute("id", workshop.GetID()); allWorkshopsXml.AddAttribute("name", workshop.GetName()); allWorkshopsXml.AddAttribute("status", workshop.GetStatus()); allWorkshopsXml.AddAttribute("duration", workshop.GetDurationAsString()); } return(this._catalogApp.GetFormattedData(allWorkshopsXml.ToString())); }
/// <summary> /// convert data from an input file to a new format and output to a new file /// this function could be broken down into smaller functions /// i.e. getData, convertData, writeData functions /// </summary> /// <param name="inputFile"></param> /// <param name="outputFile"></param> /// <param name="convertTo"></param> static void ConvertData(string inputFile, string outputFile, string convertTo) { // initialise variables CSVService inputService = null; IService <string, string, string> outputService = null; IBuilder builder = null; Converter converter = null; // get data inputService = new CSVService(inputFile); var lines = inputService.GetAllData(); // create builder and output services dependent on new format required switch (convertTo.ToLower()) { case "xml": builder = new XMLBuilder("root", "entity"); outputService = new XMLService(outputFile); break; case "json": builder = new JSONBuilder(); outputService = new JSONService(outputFile); break; default: throw new ArgumentNullException("Invalid file format to convert to"); } // do the conversion converter = new Converter(builder); var data = converter.ConvertCSV(lines.headings, lines.data); // write the new file outputService.WriteData(data); WriteLine($"Created {convertTo} file: {outputFile}"); }
private void xm(Func<XMLBuilder, XMLBuilder> l) { if (_opt.Xml) _xmlBuilder = l(_xmlBuilder); }