/// <summary> /// Add a child into this element; /// </summary> /// <param name="newChild"></param> /// <returns></returns> public ubXML AddChild(ubXML newChild) { newChild.Parent = this; newChild.Position = _children.Count; _children.Add(newChild); return newChild; }
/// <summary> /// Load XML data from a file /// </summary> /// <param name="Path">File path</param> public static ubXML LoadFile(string Path) { ubXML result = null; ubXML current = null; FileStream fs = new FileStream(Path, FileMode.Open); XmlTextReader xmlReader = new XmlTextReader(fs); try { while (xmlReader.Read()) { switch (xmlReader.NodeType) { case XmlNodeType.Element: if (result == null) { result = new ubXML(xmlReader.Name); current = result; } else { // So this is a child element, move inside it current = current.AddChild(new ubXML(xmlReader.Name)); } // Now, get all the attributes of this element if (xmlReader.AttributeCount > 0) { while (xmlReader.MoveToNextAttribute()) { current.Attrs.Add(xmlReader.Name, xmlReader.Value); } } break; case XmlNodeType.Text: current.Value = xmlReader.Value; break; case XmlNodeType.EndElement: current = current.Parent; break; } } } catch { } finally { xmlReader.Close(); fs.Close(); } return result; }