/// <summary> 
        /// Populates the data for the lap from the XML.
        /// </summary>
        /// 
        /// <param name="navigator"> 
        /// The XML node representing the lap.
        /// </param>
        /// 
        /// <exception cref="ArgumentNullException">
        /// The <paramref name="navigator"/> parameter is <b>null</b>.
        /// </exception>
        /// 
        public override void ParseXml(XPathNavigator navigator)
        {
            Validator.ThrowIfNavigatorNull(navigator);

            // activity
            _activity = XPathHelper.GetOptNavValue<CodableValue>(navigator, "activity");

            // title
            _title =
                XPathHelper.GetOptNavValue(navigator, "title");

            // distance
            _distance = XPathHelper.GetOptNavValue<Length>(navigator, "distance");

            // duration
            _duration =
                XPathHelper.GetOptNavValueAsDouble(navigator, "duration");

            // offset
            _offset =
                XPathHelper.GetOptNavValueAsDouble(navigator, "offset");

            // details
            XPathNodeIterator detailsIterator = navigator.Select("detail");

            _details.Clear();
            foreach (XPathNavigator detailsNavigator in detailsIterator)
            {
                ExerciseDetail exerciseDetail = new ExerciseDetail();
                exerciseDetail.ParseXml(detailsNavigator);

                _details.Add(exerciseDetail.Name.Value, exerciseDetail);
            }
        }
예제 #2
0
        /// <summary>
        /// Populates this <see cref="Exercise"/> instance from the data in the XML.
        /// </summary>
        /// 
        /// <param name="typeSpecificXml">
        /// The XML to get the exercise data from.
        /// </param>
        /// 
        /// <exception cref="InvalidOperationException">
        /// If the first node in <paramref name="typeSpecificXml"/> is not
        /// an "exercise" node.
        /// </exception>
        /// 
        protected override void ParseXml(IXPathNavigable typeSpecificXml)
        {
            XPathNavigator itemNav =
                typeSpecificXml.CreateNavigator().SelectSingleNode("exercise");

            Validator.ThrowInvalidIfNull(itemNav, "ExerciseUnexpectedNode");

            // when
            _when = new ApproximateDateTime();
            _when.ParseXml(itemNav.SelectSingleNode("when"));

            // activity
            _activity = XPathHelper.GetOptNavValue<CodableValue>(itemNav, "activity");

            // title
            _title =
                XPathHelper.GetOptNavValue(itemNav, "title");

            _distance =
                    XPathHelper.GetOptNavValue<Length>(itemNav, "distance");

            // duration
            _duration =
                XPathHelper.GetOptNavValueAsDouble(itemNav, "duration");

            // detail
            XPathNodeIterator detailsIterator = itemNav.Select("detail");

            _details.Clear();
            foreach (XPathNavigator detailsNavigator in detailsIterator)
            {
                ExerciseDetail exerciseDetail = new ExerciseDetail();
                exerciseDetail.ParseXml(detailsNavigator);

                _details.Add(exerciseDetail.Name.Value, exerciseDetail);
            }

            // segment
            XPathNodeIterator segmentsIterator = itemNav.Select("segment");

            _segments.Clear();
            foreach (XPathNavigator segmentsNavigator in segmentsIterator)
            {
                ExerciseSegment exerciseSegment = new ExerciseSegment();
                exerciseSegment.ParseXml(segmentsNavigator);

                _segments.Add(exerciseSegment);
            }
        }