public void Read(XmlTextReader reader) { m_fileLine = reader.LineNumber; if (reader.HasAttributes) { for (int i = 0; i < reader.AttributeCount; i++) { reader.MoveToAttribute(i); if (m_subElements == null) { m_subElements = new List <ITreeDataElement>(); } m_subElements.Add(new TreeDataElement(this, reader.Name, reader.Value)); } reader.MoveToElement(); } while (reader.Read()) { switch (reader.NodeType) { case XmlNodeType.Text: m_value = reader.ReadString(); return; case XmlNodeType.Element: { TreeDataElement sub = new TreeDataElement(this, reader.LocalName); if (m_subElements == null) { m_subElements = new List <ITreeDataElement>(); } m_subElements.Add(sub); if (reader.IsEmptyElement) { continue; } else { sub.Read(reader); } } break; case XmlNodeType.EndElement: case XmlNodeType.Whitespace: return; case XmlNodeType.Comment: break; default: throw new Exception("Error reading file in line " + reader.LineNumber.ToString() + "."); } } }
public TreeDataElement AddElement(TreeDataElement element) { element.m_parent = this; if (m_subElements == null) { m_subElements = new List <ITreeDataElement>(); } m_subElements.Add(element); return(element); }
public static TreeDataElement ReadFile(string path) { using (var reader = new XmlTextReader(path)) { reader.WhitespaceHandling = WhitespaceHandling.None; reader.Read(); if (reader.NodeType != XmlNodeType.XmlDeclaration) { throw new Exception("Error reading file in line " + reader.LineNumber.ToString() + "."); } reader.Read(); while (reader.NodeType == XmlNodeType.Comment) { reader.Read(); } TreeDataElement root = new TreeDataElement(null, reader.LocalName); root.Read(reader); return(root); } }