Esempio n. 1
0
        public static bool FromFile(this DynNode node, string fileName)
        {
            Contract.Requires(node != null);
            if (!File.Exists(fileName))
            {
                return(false);
            }
            var xmlDoc   = new XmlDocument();
            var fileText = File.ReadAllText(fileName);

            try
            {
                xmlDoc.LoadXml(fileText);
            }
            catch (XmlException ex)
            {
                Console.WriteLine(ex.Message);
                return(false);
            }

            var result = node;

            foreach (XmlNode xmlNode in xmlDoc.ChildNodes)
            {
                UpdateData(result, xmlNode);
            }
            return(true);
        }
Esempio n. 2
0
        private static void UpdateData(DynNode result, XmlNode node)
        {
            result.Name = node.Name;
            if (node.Name == "#text")
            {
                result.InnerText = node.InnerText;
            }
            result.Children.Clear();
            foreach (XmlNode xmlNode in node.ChildNodes)
            {
                UpdateData(result.Add(xmlNode.Name), xmlNode);
            }
            var attributes = node.Attributes;

            result.Attributes.Clear();
            if (attributes == null)
            {
                return;
            }
            foreach (XmlAttribute attribute in attributes)
            {
                result[attribute.Name] = attribute.Value;
            }
        }
Esempio n. 3
0
 public static void ToFile(this DynNode node, string fileName)
 {
     CreateFolderForFile(fileName);
     File.WriteAllText(fileName, node.ToString());
 }