Beispiel #1
0
    public static void Save(EntityParamModel param, string path)
    {
        string xml = EntityParam.ToXml(param);

        if (!string.IsNullOrEmpty(path))
        {
            File.WriteAllText(path, xml, System.Text.Encoding.UTF8);
        }
    }
Beispiel #2
0
    public static string ToXml(EntityParam root)
    {
        root.children.Sort(Sort);

        XmlDocument    doc = new XmlDocument();
        XmlDeclaration dec = doc.CreateXmlDeclaration("1.0", "utf-8", "yes");

        doc.InsertBefore(dec, doc.DocumentElement);

        doc.AppendChild(root.ToXml(doc));

        MemoryStream  ms = new MemoryStream();
        XmlTextWriter xw = new XmlTextWriter(ms, System.Text.Encoding.UTF8);

        xw.Formatting = Formatting.Indented;
        doc.Save(xw);

        ms = (MemoryStream)xw.BaseStream;
        byte[] bytes = ms.ToArray();
        string xml   = System.Text.Encoding.UTF8.GetString(bytes, 3, bytes.Length - 3);

        return(xml);
    }