Example #1
0
        private void CreateNamedElement(string name)
        {
            var creaElement = new DynNode(name);

            Top().Children.Add(creaElement);
            _stack.Push(creaElement);
        }
Example #2
0
        public byte[] Minimize(DynNode node, bool compress)
        {
            Process(node);
            var resultArray = Result.ToArray();

            return(!compress
                ? resultArray
                : resultArray.Compress());
        }
Example #3
0
        private void Process(DynNode node)
        {
            if (node.Name == "#text")
            {
                CreateOrUpdateItemWithText(node.InnerText, ExiLikeEvent.ExistingText, ExiLikeEvent.CreateText, _dict);
                return;
            }
            CreateOrUpdateItemWithText(node.Name, ExiLikeEvent.ExistingElement, ExiLikeEvent.CreateElement,
                                       _elementsDict);

            foreach (var attr in node.Attributes)
            {
                CreateOrUpdateItemWithText(attr.Key, ExiLikeEvent.ExistingAttribute, ExiLikeEvent.CreateAttribute,
                                           _elementsDict);
                CreateOrUpdateItemWithText(attr.Value, ExiLikeEvent.ExistingAttributeValue,
                                           ExiLikeEvent.CreateAttributeValue, _dict);
            }
            foreach (var child in node.Children)
            {
                Process(child);
            }
            PushEvent(ExiLikeEvent.EndElement);
        }
Example #4
0
        public DynNode Expand(byte[] arrayData, bool decompress)
        {
            if (decompress)
            {
                arrayData = arrayData.Decompress();
            }

            _cursor.ArrayData = arrayData;
            var ev   = _cursor.Next();
            var root = new DynNode(_cursor.ReadString());

            _stack.Push(root);

            var attrKey = string.Empty;

            do
            {
                ev = _cursor.Next();
                switch (ev)
                {
                case ExiLikeEvent.CreateElement:
                    CreateNewElement();
                    break;

                case ExiLikeEvent.ExistingElement:
                    CreateExistingElement();
                    break;

                case ExiLikeEvent.CreateAttribute:
                    attrKey = CreateAttrKey();
                    break;

                case ExiLikeEvent.ExistingAttribute:
                    attrKey = ExistingAttrKey();
                    break;

                case ExiLikeEvent.CreateAttributeValue:
                    CreateAttrValue(attrKey);
                    break;

                case ExiLikeEvent.ExistingAttributeValue:
                    ExistingAttrValue(attrKey);
                    break;

                case ExiLikeEvent.CreateText:
                    CreateText();
                    break;

                case ExiLikeEvent.ExistingText:
                    ExistingText();
                    break;

                case ExiLikeEvent.EndElement:
                    _stack.Pop();
                    if (_stack.Count == 0)
                    {
                        return(root);
                    }
                    break;
                }
            } while (ev != ExiLikeEvent.None);
            return(root);
        }