Example #1
0
        protected void HandleChunk(XmlTextReader xml)
        {
            int      lookingFor = 0;         // 0 = nothing, 1 = key, 2 = value
            string   key        = null;
            NodeType type       = NodeType.String;
            string   data       = null;
            DataNode node       = null;

            while (xml.Read())
            {
                if (xml.NodeType == XmlNodeType.Element)
                {
                    if (xml.Name == KEY_STRING)
                    {
                        lookingFor = 1;
                    }
                    else if (xml.Name == VALUE_STRING)
                    {
                        string strType = xml.GetAttribute(TYPE_ATTR);

                        lookingFor = 2;

                        switch (strType)
                        {
                        case TYPE_INT:
                            type = NodeType.Int;
                            break;

                        case TYPE_DOUBLE:
                            type = NodeType.Double;
                            break;

                        case TYPE_XML:
                            type       = NodeType.Xml;
                            lookingFor = 0;
                            break;
                        }
                    }
                }
                else if (xml.NodeType == XmlNodeType.Text)
                {
                    switch (lookingFor)
                    {
                    case 1:
                        key = xml.Value;
                        break;

                    case 2:
                        data = xml.Value;
                        break;
                    }

                    lookingFor = 0;
                }
                else if (xml.NodeType == XmlNodeType.EndElement &&
                         xml.Name == CHUNK_STRING)
                {
                    switch (type)
                    {
                    case NodeType.String:
                        node = new StringNode(data);
                        break;

                    case NodeType.Int:
                        node = new IntNode(Int32.Parse(data));
                        break;

                    case NodeType.Double:
                        node = new DoubleNode(Double.Parse(data));
                        break;

                    case NodeType.Xml:
                        break;
                    }

                    break;
                }
            }

            if (key != null && node != null)
            {
                _data[key] = node;
            }
        }
Example #2
0
        public void Set(string key, string data)
        {
            StringNode s = new StringNode(data);

            StoreData(key, s);
        }