// -------------------------------------------------------------------------------
        // -------------------------------------------------------------------------------
        /// <summary>
        /// Loads the RssMediaText object properties with the contents of the XElement
        /// </summary>
        /// <param name="parEl">Parent XElement</param>
        // -------------------------------------------------------------------------------
        // -------------------------------------------------------------------------------
        public void Load(XElement parEl)
        {
            if (parEl.Name.Namespace == RSS.MEDIA_NS)
            {
                text = xUtil.GetStr(parEl);

                IEnumerable <XAttribute> lstAttr = parEl.Attributes();
                foreach (XAttribute attr in lstAttr)
                {
                    switch (attr.Name.LocalName)
                    {
                    case ATTR_TYPE:
                        type = xUtil.GetAttrStr(attr);
                        break;

                    case ATTR_LANG:
                        lang = xUtil.GetAttrStr(attr);
                        break;

                    case ATTR_START:
                        start = xUtil.GetAttrTimeSpan(attr);
                        break;

                    case ATTR_END:
                        end = xUtil.GetAttrTimeSpan(attr);
                        break;
                    }
                }
            }
        }
        // -------------------------------------------------------------------------------
        // -------------------------------------------------------------------------------
        /// <summary>
        /// Loads the properties of the RssMediaThumbnail object from an XElement
        /// </summary>
        /// <param name="parEl"></param>
        // -------------------------------------------------------------------------------
        // -------------------------------------------------------------------------------
        public void Load(XElement parEl)
        {
            if (parEl.Name.Namespace == RSS.MEDIA_NS)
            {
                IEnumerable <XAttribute> lstAttr = parEl.Attributes();
                foreach (XAttribute attr in lstAttr)
                {
                    switch (attr.Name.LocalName)
                    {
                    case ATTR_URL:
                        url = xUtil.GetAttrStr(attr);
                        break;

                    case ATTR_WIDTH:
                        width = xUtil.GetAttrInt(attr);
                        break;

                    case ATTR_HEIGHT:
                        height = xUtil.GetAttrInt(attr);
                        break;

                    case ATTR_TIME:
                        time = xUtil.GetAttrTimeSpan(attr);
                        break;
                    }
                }
            }
        }
Ejemplo n.º 3
0
        // -------------------------------------------------------------------------------
        // -------------------------------------------------------------------------------
        /// <summary>
        /// Loads RssMediaLocation object properties with contents of parent XElement
        /// </summary>
        /// <param name="parEl">Parent XElement</param>
        // -------------------------------------------------------------------------------
        // -------------------------------------------------------------------------------
        public void Load(XElement parEl)
        {
            IEnumerable <XAttribute> lstAttr = parEl.Attributes();

            foreach (XAttribute attr in lstAttr)
            {
                switch (attr.Name.LocalName)
                {
                case ATTR_DESCRIPTION:
                    description = xUtil.GetAttrStr(attr);
                    break;

                case ATTR_START:
                    start = xUtil.GetAttrTimeSpan(attr);
                    break;

                case ATTR_END:
                    end = xUtil.GetAttrTimeSpan(attr);
                    break;
                }
            }

            // get all teh subelements to location.  should be 1, where
            IEnumerable <XElement> LocationChildren = parEl.Elements();

            foreach (XElement elLocationChild in LocationChildren)
            {
                // only check the elements that are in the georss namespace
                if (elLocationChild.Name.Namespace == RSS.GEORSS_NS)
                {
                    switch (elLocationChild.Name.LocalName)
                    {
                    case TAG_WHERE:

                        IEnumerable <XElement> WhereChildren = elLocationChild.Elements();
                        foreach (XElement WhereChild in WhereChildren)
                        {
                            // if the namespace of the where child is gml, then we should procced
                            if (WhereChild.Name.Namespace == RSS.GML_NS)
                            {
                                switch (WhereChild.Name.LocalName)
                                {
                                case TAG_POINT:

                                    IEnumerable <XElement> PointChildren = WhereChild.Elements();
                                    foreach (XElement PointChild in PointChildren)
                                    {
                                        // if the namespace of point child is GMLNs, then
                                        // we proceed as we are looking for gml:pos
                                        if (PointChild.Name.Namespace == RSS.GML_NS)
                                        {
                                            switch (PointChild.Name.LocalName)
                                            {
                                            case TAG_POS:

                                                // get the tag value.  it is a string with
                                                // a latitude and longitude separated by a
                                                // space.
                                                string coordinates = xUtil.GetStr(PointChild);
                                                coordinates = coordinates.Trim();

                                                if (coordinates.Length > 0)
                                                {
                                                    string[] a = coordinates.Split(' ');

                                                    // now iterate the array taking the first two
                                                    // non blank values as the data
                                                    string[] latlong = new string[2];
                                                    int      ndx     = 0;
                                                    for (int j = 0; j < a.Length; j++)
                                                    {
                                                        string tmp = a[j].Trim();
                                                        if (tmp.Length > 0 && ndx <= 1)
                                                        {
                                                            latlong[ndx] = tmp;
                                                            ndx         += 1;
                                                        }
                                                    }
                                                    if (double.TryParse(latlong[0], out double tmplat))
                                                    {
                                                        latitude = tmplat;
                                                    }
                                                    if (double.TryParse(latlong[1], out double tmplong))
                                                    {
                                                        longitude = tmplong;
                                                    }
                                                }               // end if position

                                                break;
                                            }   // end switch
                                        }       // end if point child in gml namespace
                                    }           // end foreach point child element


                                    break;
                                } // end switch "where"
                            }     // end if where child element is in georss namespace
                        }         // end foreach child of where element


                        break;
                    } // end switch
                }     // end if location child is in georss namespace
            }         // end foreach child of georss:where element
        }   // end load