Exemplo n.º 1
0
        public async void GetRequest()
        {
            //Check network status
            if (NetworkCheck.IsInternet())
            {
                Uri                 geturi      = new Uri("https://yastatic.net/market-export/_/partner/help/YML.xml");
                HttpClient          client      = new HttpClient();
                HttpResponseMessage responseGet = await client.GetAsync(geturi);

                string response = await responseGet.Content.ReadAsStringAsync();//Getting response

                //Xml Parsing
                List <XmlOfferDetails> ObjOfferList = new List <XmlOfferDetails>();
                XDocument doc = XDocument.Parse(response);
                foreach (var item in doc.Descendants("offer"))
                {
                    XmlOfferDetails ObjOfferItem = new XmlOfferDetails();
                    ObjOfferItem.Id        = item.Attribute("id").Value.ToString();
                    ObjOfferItem.Type      = item.Attribute("type").Value.ToString();
                    ObjOfferItem.Bid       = item.Attribute("bid").Value.ToString();
                    ObjOfferItem.Available = item.Attribute("available").Value.ToString();
                    ObjOfferList.Add(ObjOfferItem);
                }
                //Binding listview with server response
                listviewOffer.ItemsSource = ObjOfferList;
            }
            else
            {
                await DisplayAlert("XmlParsing", "No network is available.", "Ok");
            }
            //Hide loader after server response
            ProgressLoader.IsRunning = false;
        }
Exemplo n.º 2
0
        public DetailsPage(XmlOfferDetails item)
        {
            InitializeComponent();
            // создаем DataContractJsonSerializer
            DataContractJsonSerializer formatter = new DataContractJsonSerializer(typeof(XmlOfferDetails));

            // создаем поток (json файл)
            MemoryStream stream = new MemoryStream();

            // сериализация (сохранение объекта в поток)
            formatter.WriteObject(stream, item);

            selected.Text = Encoding.Default.GetString((stream.ToArray()));
            GridDetails.BindingContext = item;
        }