c# - Export a collection of objects (which in turn contains a collection object) to xml -
I have a data object class that stores many properties. Is a folder, and the second one is a What I need to do is write it in xml, as follows: Is this easily possible? Or is there an external library which can easily do it for me? Thanks Use Xml Serializer to work for you? What Output There are some cornucas and glax, especially when working with existing XSD, but this is very misleading and documented elsewhere. string [] of all the files in that array.
& lt; X & gt; & Lt; A & gt; Dir & lt; / A & gt; & Lt; P & gt; File & lt; / H> Then all the files (there is a
string [] data per object array), the directory is nested below the field.
using System.Linq; Using System.Collections.Generic; Using System.Xml.Serialization; Using System.IO; Using the system; Nomenclature ns {public class data {public class nested {public string {get; Set; } Public string [] content = {"lazy guy jumped", "the", "moon"}; } Public List & Nested & gt; item; } Static Class Helper {public Static String Toxml & lt; T & gt; (It's T. O.B.J.) where T: class, new () {if (null == obj) empty return; (Var mem = new memorystream ()) using {var ser = new XML serializer (typef (t)); Ser.Serialize (mem, OBJ); Return System. Text. Encoding.Utf 8.GetString (M. Toure ()); }} Public stable t fromXml & lt; T & gt; (This string xml) where T: new () (using var mem = new memorystream (System.Text.Encoding.UTF8.GetBytes (xml)) {var ser = new XmlSerializer (typeof (T)); Return (T) service. Directory (mem);}}} class program {public static zero main (string [] args) {var data = new data {item = new list & lt; data. Nested & gt; {new data. Nested {the = "1"}}} Console.WriteLine (data.ToXml ()); Var clone = Data. ToXml (). FromXml & lt; data & gt; (); console.light line ("Disaryized: {0} ", context references (data, x Console. Light Line ("Similar: {0}", Equal (Data. Toxml (), Clone.Tonxml ());}}}
& lt; xml version = "1.0" encoding = "UTF-8"? & Gt; data xmlns: xsi = "http://www.w3.org/2001/ XMLSchema-instance "xmlns: xsd =" http://www.w3.org/2001/XMLSchema ">
Comments
Post a Comment