示例#1
0
        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);
            }
        }
示例#2
0
        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);
            }
        }
示例#3
0
        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();
        }
示例#4
0
 public XmlParser(string fileName, InformationElements rootElementt)
 {
     this.fileName     = fileName;
     this.rootElementt = rootElementt;
 }
示例#5
0
 public PrintXML(InformationElements rootElement)
 {
     rootElements = rootElement;
 }