示例#1
0
        public void ReadXml(System.Xml.XmlReader reader)
        {
            XmlSerializer serializer;

            if (!reader.Read())
            {
                return;
            }

            reader.ReadStartElement("type");
            _type = (VariantType)reader.ReadContentAsInt();
            reader.ReadEndElement();

            reader.ReadStartElement("value");

            switch (_type)
            {
            case VariantType.Int:
                _valueInt = reader.ReadContentAsInt();
                break;

            case VariantType.Long:
                _valueLong = reader.ReadContentAsLong();
                break;

            case VariantType.ULong:
                _valueULong = (ulong)reader.ReadContentAsLong();
                break;

            case VariantType.Double:
                _valueDouble = (double)reader.ReadContentAsDouble();
                break;

            case VariantType.String:
                _valueString = reader.ReadContentAsString();
                break;

            case VariantType.ByteString:
                serializer      = new XmlSerializer(typeof(byte[]));
                _valueByteArray = (byte[])serializer.Deserialize(reader);
                break;

            case VariantType.BitStream:
                serializer      = new XmlSerializer(typeof(BitwiseStream));
                _valueBitStream = (BitwiseStream)serializer.Deserialize(reader);
                break;
            }

            reader.ReadEndElement();
        }
示例#2
0
        void ITwentyThreeParsable.Load(System.Xml.XmlReader reader)
        {
            while (reader.MoveToNextAttribute())
            {
                switch (reader.LocalName)
                {
                case "created":
                    DateCreated = UtilityMethods.UnixTimestampToDate(reader.Value);
                    break;

                case "alpha":
                    Alpha = reader.ReadContentAsDouble();
                    break;

                case "count_points":
                    PointCount = reader.ReadContentAsInt();
                    break;

                case "count_edges":
                    EdgeCount = reader.ReadContentAsInt();
                    break;

                case "has_donuthole":
                    HasDonutHole = reader.Value == "1";
                    break;

                case "is_donuthole":
                    IsDonutHole = reader.Value == "1";
                    break;

                default:
                    UtilityMethods.CheckParsingException(reader);
                    break;
                }
            }

            reader.Read();

            while (reader.NodeType != System.Xml.XmlNodeType.EndElement)
            {
                switch (reader.LocalName)
                {
                case "polylines":
                    reader.Read();
                    while (reader.LocalName == "polyline")
                    {
                        var      polyline   = new Collection <PointD>();
                        string   polystring = reader.ReadElementContentAsString();
                        string[] points     = polystring.Split(' ');
                        foreach (string point in points)
                        {
                            string[] xy = point.Split(',');
                            if (xy.Length != 2)
                            {
                                throw new ParsingException("Invalid polypoint found in polyline : '" + polystring +
                                                           "'");
                            }
                            polyline.Add(
                                new PointD(
                                    double.Parse(xy[0], System.Globalization.NumberFormatInfo.InvariantInfo),
                                    double.Parse(xy[1], System.Globalization.NumberFormatInfo.InvariantInfo)));
                        }
                        PolyLines.Add(polyline);
                    }
                    reader.Read();
                    break;

                case "urls":
                    reader.Skip();
                    break;
                }
            }

            reader.Read();
        }
示例#3
0
        void IFlickrParsable.Load(System.Xml.XmlReader reader)
        {
            if (reader == null)
            {
                throw new ArgumentNullException("reader");
            }
            if (reader.LocalName != "suggestion")
            {
                UtilityMethods.CheckParsingException(reader); return;
            }

            while (reader.MoveToNextAttribute())
            {
                switch (reader.LocalName)
                {
                case "id":
                    SuggestionId = reader.Value;
                    break;

                case "photo_id":
                    PhotoId = reader.Value;
                    break;

                case "date_suggested":
                    DateSuggested = UtilityMethods.UnixTimestampToDate(reader.Value);
                    break;

                default:
                    UtilityMethods.CheckParsingException(reader);
                    break;
                }
            }

            reader.Read();

            while (reader.LocalName != "suggestion" && reader.NodeType != System.Xml.XmlNodeType.EndElement)
            {
                switch (reader.LocalName)
                {
                case "suggested_by":
                    SuggestedByUserId   = reader.GetAttribute("nsid");
                    SuggestedByUserName = reader.GetAttribute("username");
                    reader.Skip();
                    break;

                case "note":
                    Note = reader.ReadElementContentAsString();
                    break;

                case "location":
                    while (reader.MoveToNextAttribute())
                    {
                        switch (reader.LocalName)
                        {
                        case "woeid":
                            WoeId = reader.Value;
                            break;

                        case "latitude":
                            Latitude = reader.ReadContentAsDouble();
                            break;

                        case "longitude":
                            Longitude = reader.ReadContentAsDouble();
                            break;

                        case "accuracy":
                            Accuracy = (GeoAccuracy)reader.ReadContentAsInt();
                            break;

                        default:
                            UtilityMethods.CheckParsingException(reader);
                            break;
                        }
                    }
                    reader.Skip();
                    break;

                default:
                    UtilityMethods.CheckParsingException(reader);
                    break;
                }
            }
        }