Example #1
0
        public void Load(TextReader projectXML)
        {
            XmlReaderSettings settings = new XmlReaderSettings();

            settings.IgnoreComments   = true;
            settings.IgnoreWhitespace = true;

            using (XmlReader reader = XmlReader.Create(projectXML))
            {
                try {
                    bool process = true;
                    // Read nodes one at a time
                    while (process)
                    {
                        reader.Read();
                        // Print out info on node
                        switch (reader.NodeType)
                        {
                        case XmlNodeType.Element:
                            if ("category".Equals(reader.Name))
                            {
                                SymbolCategory category = new SymbolCategory();
                                HandleCategory(category, reader);
                                categories.Add(category);
                            }
                            else
                            {
                                Error(reader, "unexpected tag " + reader.Name);
                            }
                            projectXML.Close();
                            process = false;
                            break;
                        }
                    }
                } catch (Exception ex) {
                    Error(reader, ex.ToString());
                    projectXML.Close();
                }
            }
            projectXML.Close();
            projectXML.Dispose();
        }
Example #2
0
        private void HandleCategory(SymbolCategory category, XmlReader reader)
        {
            string tagName = reader.Name;

            category.Name = reader.GetAttribute("name");
            log.Debug("Handle category " + category.Name);
            if (reader.IsEmptyElement)
            {
                return;
            }
            log.Indent();
            while (reader.Read())
            {
                // Print out info on node
                switch (reader.NodeType)
                {
                case XmlNodeType.Element:
                    if ("property".Equals(reader.Name))
                    {
                        string name  = reader.GetAttribute("name");
                        string value = reader.GetAttribute("value");
                        HandleProperty(reader, category.Default, reader.GetAttribute("name"), reader.GetAttribute("value"));
                        if (trace)
                        {
                            log.Trace("Property " + name + " = " + value);
                        }
                    }
                    else if ("category".Equals(reader.Name))
                    {
                        SymbolCategory subCategory = new SymbolCategory(category.Default.Copy());
                        HandleCategory(subCategory, reader);
                        category.Categories.Add(subCategory);
                    }
                    else if ("symbol".Equals(reader.Name))
                    {
                        string           name      = reader.GetAttribute("name");
                        string           universal = reader.GetAttribute("universal");
                        SymbolProperties symbol    = category.Default.Copy();
                        symbol.Symbol = name;
                        if (universal != null)
                        {
//		                        symbol.UniversalSymbol = universal;
                        }
                        HandleSymbol(symbol, reader);
                        category.Symbols.Add(symbol);
                    }
                    else
                    {
                        Error(reader, "unexpected tag " + reader.Name);
                    }
                    break;

                case XmlNodeType.EndElement:
                    if (tagName.Equals(reader.Name))
                    {
                        log.Outdent();
                        return;
                    }
                    else
                    {
                        Error(reader, "End of " + tagName + " was expected instead of end of " + reader.Name);
                    }
                    break;
                }
            }
            Error(reader, "Unexpected end of file");
            return;
        }