private static void Process(FlexBuffer flx, XmlNode element)
        {
            var node = flx.StartVector();

            flx.AddKey("tagName");
            flx.Add(element.Name);
            var attributes = element.Attributes;

            if (attributes != null)
            {
                for (var i = 0; i < attributes.Count; i++)
                {
                    var att = attributes.Item(i);
                    flx.AddKey(att.Name);
                    flx.Add(att.Value);
                }
            }

            var children = element.ChildNodes;

            if (children.Count > 0)
            {
                flx.AddKey("children");
                var childVector = flx.StartVector();
                for (var i = 0; i < children.Count; i++)
                {
                    var child = children[i];
                    if (child.NodeType == XmlNodeType.Text || child.NodeType == XmlNodeType.CDATA)
                    {
                        flx.Add(child.Value);
                    }
                    else if (child.NodeType == XmlNodeType.Comment)
                    {
                    }
                    else
                    {
                        Process(flx, child);
                    }
                }

                flx.EndVector(childVector, false, false);
            }
            flx.SortAndEndMap(node);
        }
        private void ReadString(FlexBuffer flx, bool asKey = false)
        {
            var builder = new StringBuilder();

            _scanner.Assert('"');

            while (true)
            {
                var c = _scanner.Read();

                if (c == '\\')
                {
                    c = _scanner.Read();

                    switch (char.ToLower(c))
                    {
                    case '"':                              // "
                    case '\\':                             // \
                    case '/':                              // /
                        builder.Append(c);
                        break;

                    case 'b':
                        builder.Append('\b');
                        break;

                    case 'f':
                        builder.Append('\f');
                        break;

                    case 'n':
                        builder.Append('\n');
                        break;

                    case 'r':
                        builder.Append('\r');
                        break;

                    case 't':
                        builder.Append('\t');
                        break;

                    case 'u':
                        builder.Append(ReadUnicodeLiteral());
                        break;

                    default:
                        throw new Exception($"Unexpected character {_scanner.Position}");
                    }
                }
                else if (c == '"')
                {
                    break;
                }
                else
                {
                    if (char.IsControl(c))
                    {
                        throw new Exception($"Unexpected character {_scanner.Position}");
                    }
                    else
                    {
                        builder.Append(c);
                    }
                }
            }

            if (asKey)
            {
                flx.AddKey(builder.ToString());
            }
            else
            {
                flx.Add(builder.ToString());
            }
        }
예제 #3
0
 public void AddNull(string key)
 {
     _buffer.AddKey(key);
     _buffer.AddNull();
 }