public void Parse() { StreamReader streamReader = new StreamReader(fileName); string xmlLines = streamReader.ReadToEnd(); InformationElements currentNode = rootElementt; while (xmlLines.Length > 0) { ParsedItem parsedItem = FindItem(xmlLines); switch (parsedItem.types) { case ItemTypes.OpenTag: currentNode = currentNode.AddChild(parsedItem.tag, parsedItem.element); break; case ItemTypes.CloseTag: currentNode = currentNode.GetParent(); break; case ItemTypes.ToSkip: break; } int nextTag = xmlLines.IndexOf('<', 1); if (nextTag < 0) { break; } xmlLines = xmlLines.Substring(nextTag); } }
public void PrintChild(InformationElements node, string path) { path += "-" + node.tag; if (node.element != null) { Console.WriteLine("{0}-{1}", path, node.element); } node.children.Sort(); for (int i = 0; i < node.children.Count; i++) { PrintChild(node.children[i], path); } }
static void Main(string[] args) { InformationElements rootElement = new InformationElements(null, "", ""); if (args.Length == 1) { XmlParser xmlParser = new XmlParser(args[0], rootElement); xmlParser.Parse(); } PrintXML printXML = new PrintXML(rootElement); printXML.Print(); }
public XmlParser(string fileName, InformationElements rootElementt) { this.fileName = fileName; this.rootElementt = rootElementt; }
public PrintXML(InformationElements rootElement) { rootElements = rootElement; }