AppendChild() public méthode

public AppendChild ( Node child ) : void
child Node
Résultat void
Exemple #1
0
        private void ReadNode(Node node)
        {
            UInt32 nodeNameId     = reader.ReadUInt32();
            UInt32 attributeCount = reader.ReadUInt32();
            UInt32 childCount     = reader.ReadUInt32();

            node.Name = staticStrings[nodeNameId];

            for (UInt32 i = 0; i < attributeCount; i++)
            {
                UInt32 attrNameId = reader.ReadUInt32();
                UInt32 attrTypeId = reader.ReadUInt32();
                if (attrTypeId > (int)NodeAttribute.DataType.DT_Max)
                {
                    throw new InvalidFormatException(String.Format("Unsupported attribute data type: {0}", attrTypeId));
                }

                node.Attributes[staticStrings[attrNameId]] = ReadAttribute((NodeAttribute.DataType)attrTypeId);
            }

            for (UInt32 i = 0; i < childCount; i++)
            {
                Node child = new Node();
                child.Parent = node;
                ReadNode(child);
                node.AppendChild(child);
            }
        }
Exemple #2
0
        private Node ReadNode(JsonReader reader, Node node)
        {
            string key = "";

            while (reader.Read())
            {
                if (reader.TokenType == JsonToken.EndObject)
                {
                    break;
                }
                else if (reader.TokenType == JsonToken.PropertyName)
                {
                    key = reader.Value.ToString();
                }
                else if (reader.TokenType == JsonToken.StartObject)
                {
                    var attribute = ReadAttribute(reader);
                    node.Attributes.Add(key, attribute);
                }
                else if (reader.TokenType == JsonToken.StartArray)
                {
                    while (reader.Read())
                    {
                        if (reader.TokenType == JsonToken.EndArray)
                        {
                            break;
                        }
                        else if (reader.TokenType == JsonToken.StartObject)
                        {
                            var childNode = new Node();
                            childNode.Name = key;
                            ReadNode(reader, childNode);
                            node.AppendChild(childNode);
                            childNode.Parent = node;
                        }
                        else
                        {
                            throw new InvalidDataException("Unexpected JSON token during parsing of child node list: " + reader.TokenType);
                        }
                    }
                }
                else
                {
                    throw new InvalidDataException("Unexpected JSON token during parsing of node: " + reader.TokenType);
                }
            }

            return(node);
        }
Exemple #3
0
        private void ReadNode(Node node)
        {
            UInt32 nodeNameId = reader.ReadUInt32();
            UInt32 attributeCount = reader.ReadUInt32();
            UInt32 childCount = reader.ReadUInt32();
            node.Name = staticStrings[nodeNameId];

            for (UInt32 i = 0; i < attributeCount; i++)
            {
                UInt32 attrNameId = reader.ReadUInt32();
                UInt32 attrTypeId = reader.ReadUInt32();
                if (attrTypeId > (int)NodeAttribute.DataType.DT_Max)
                    throw new InvalidFormatException(String.Format("Unsupported attribute data type: {0}", attrTypeId));

                node.Attributes[staticStrings[attrNameId]] = ReadAttribute((NodeAttribute.DataType)attrTypeId);
            }

            for (UInt32 i = 0; i < childCount; i++)
            {
                Node child = new Node();
                child.Parent = node;
                ReadNode(child);
                node.AppendChild(child);
            }
        }