Xml parse and binding to listview on xamarin formsHow does one parse XML files?How can I build XML in C#?Best way to parse command line arguments in C#?How do I read and parse an XML file in C#?What characters do I need to escape in XML documents?How do I parse XML in Python?How do I comment out a block of tags in XML?What does <![CDATA[]]> in XML mean?How do you parse and process HTML/XML in PHP?Xamarin Forms Binding. How to display 1 of 3 different strings based on some conditions

Is it right to use the ideas of non-winning designers in a design contest?

Was Rosie the Riveter sourced from a Michelangelo painting?

Was the lunar landing site always in the same plane as the CM's orbit?

Can Adventure creatures always be cast from exile?

Is Sanskrit really the mother of all languages?

Is it a missed optimization, when a compile-time known reference takes space in a struct?

First Number to Contain Each Letter

Why does 8 bit truecolor use only 2 bits for blue?

Golfball Dimples on spaceships (and planes)?

What makes an ending "happy"?

Is there some sort of French saying for "a person's signature move"?

Sinning and G-d's will, what's wrong with this logic?

Temporarily simulate being offline programmatically

Are there mathematical concepts that exist in the fourth dimension, but not in the third dimension?

How does the UK House of Commons think they can prolong the deadline of Brexit?

Why is Sojdlg123aljg a common password?

My Friend James

In apex, how to replace the value in the string

Fantasy Military Arms and Armor: the Dwarven Grand Armory

Do 643,000 Americans go bankrupt every year due to medical bills?

Infinitely many primes

Need help figure out a Fibonacci related math trick

Project Euler Problem 45

GFI outlets tripped after power outage



Xml parse and binding to listview on xamarin forms


How does one parse XML files?How can I build XML in C#?Best way to parse command line arguments in C#?How do I read and parse an XML file in C#?What characters do I need to escape in XML documents?How do I parse XML in Python?How do I comment out a block of tags in XML?What does <![CDATA[]]> in XML mean?How do you parse and process HTML/XML in PHP?Xamarin Forms Binding. How to display 1 of 3 different strings based on some conditions






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;








0















Hi I am trying to parse XML in my xamarin.forms app.The xml data contains one transactionID and couple of questions with multiple answers. What Iam trying to achieve is Bind the questions in to label and and answers into dropdowns in a listview.



The XML Iam getting from API



<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<PlatformResponse>
<TransactionDetails>
<TransactId>39562</TransactionId>
</TransactionDetails>
<Response>
<Questions>
<Question type="1" text="Which one is correct?">
<Answer correct="false">test1</Answer>
<Answer correct="false">test2</Answer>
<Answer correct="false">test3</Answer>
<Answer correct="false">test4</Answer>
<Answer correct="false">test5</Answer>
<Answer correct="false">test5</Answer>
</Question>
<Question type="2" text="Which one is associated with you?">
<Answer correct="false">test1</Answer>
<Answer correct="false">test2</Answer>
<Answer correct="false">test3</Answer>
<Answer correct="false">test4</Answer>
<Answer correct="false">test5</Answer>
<Answer correct="false">test5</Answer>
</Question>
<Question type="3" text="Which one of the following is true ?">
<Answer correct="false">test1</Answer>
<Answer correct="false">test2</Answer>
<Answer correct="false">test3</Answer>
<Answer correct="false">test4</Answer>
<Answer correct="false">test5</Answer>
<Answer correct="false">test5</Answer>
</Question>
</Questions>
</Response>
</PlatformResponse>


How Iam parsing it



 HttpWebRequest webRequest = (HttpWebRequest)WebRequest.Create(url);
webRequest.ProtocolVersion = HttpVersion.Version10;
webRequest.Method = "POST";
webRequest.ContentType = "text/xml charset=utf8";
webRequest.ContentLength = postData.Length;
Stream requestStream = webRequest.GetRequestStream();
requestStream.Write(postData, 0, postData.Length);
requestStream.Close();
HttpWebResponse webResponse = (HttpWebResponse)webRequest.GetResponse();
StreamReader reader = new StreamReader(webResponse.GetResponseStream());
string reader2 = reader.ReadToEnd();
List<XmlData> ObjXmlData = new List<XmlData>();
XDocument doc = XDocument.Parse(reader2);

// How Can I bind it to the listview


My Data Model



 public class XmlData

public string TransactionId get; set;
public string Question get; set;
public string Answer get; set;



My List View



 <ListView x:Name="QuestionsListView" ItemsSource="Binding"
HasUnevenRows="True"
HorizontalOptions="FillAndExpand"
VerticalOptions="FillAndExpand">
<ListView.ItemTemplate>
<DataTemplate>
<ViewCell>
<ViewCell.View>
<StackLayout>
<StackLayout Orientation="Horizontal">
<Label Text="•" FontSize="Medium" TextColor="Green" Margin="0,20,0,0"/>
<Label Text="Binding Question" FontSize="Small" TextColor="#474747" Margin="0,20,0,0">
</Label>
</StackLayout>
<StackLayout Orientation="Horizontal" Margin="10,0,10,0" HorizontalOptions="FillAndExpand" >
<Picker x:Name="picker1" Title="Select answer" ItemDisplayBinding="Binding Answer" HorizontalOptions="FillAndExpand" FontSize="Small" TextColor="Gray">
</Picker>
<Image Source="downarrow.png" HorizontalOptions="End" HeightRequest="20" WidthRequest="20" ></Image>
</StackLayout>
</StackLayout>
</ViewCell.View>
</ViewCell>
</DataTemplate>
</ListView.ItemTemplate>
</ListView

>


How Can I bind these questions and answers to picker and label. Any help appreciated.










share|improve this question


























  • 1) Do you want to flatten your XDocument to your model? OR 2) Do you want to bind your model to list view?

    – er-sho
    Mar 28 at 5:54











  • @er-sho I want to parse the xml and bind it to my listview

    – AndroDevil
    Mar 28 at 5:57











  • @er-sho where iam stuck is creating a view model according to the xml and binding to the listview after parse

    – AndroDevil
    Mar 28 at 5:58











  • means you have 2 question in same post, could you please edit your post and ask these 2 question in different post. otherwise most likely your post has been marked as to broad by users.

    – er-sho
    Mar 28 at 6:18











  • @er-sho Bro sorry. My question is How can I make the xml to bind to the listview.Iam stuck at creating the data model

    – AndroDevil
    Mar 28 at 6:21

















0















Hi I am trying to parse XML in my xamarin.forms app.The xml data contains one transactionID and couple of questions with multiple answers. What Iam trying to achieve is Bind the questions in to label and and answers into dropdowns in a listview.



The XML Iam getting from API



<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<PlatformResponse>
<TransactionDetails>
<TransactId>39562</TransactionId>
</TransactionDetails>
<Response>
<Questions>
<Question type="1" text="Which one is correct?">
<Answer correct="false">test1</Answer>
<Answer correct="false">test2</Answer>
<Answer correct="false">test3</Answer>
<Answer correct="false">test4</Answer>
<Answer correct="false">test5</Answer>
<Answer correct="false">test5</Answer>
</Question>
<Question type="2" text="Which one is associated with you?">
<Answer correct="false">test1</Answer>
<Answer correct="false">test2</Answer>
<Answer correct="false">test3</Answer>
<Answer correct="false">test4</Answer>
<Answer correct="false">test5</Answer>
<Answer correct="false">test5</Answer>
</Question>
<Question type="3" text="Which one of the following is true ?">
<Answer correct="false">test1</Answer>
<Answer correct="false">test2</Answer>
<Answer correct="false">test3</Answer>
<Answer correct="false">test4</Answer>
<Answer correct="false">test5</Answer>
<Answer correct="false">test5</Answer>
</Question>
</Questions>
</Response>
</PlatformResponse>


How Iam parsing it



 HttpWebRequest webRequest = (HttpWebRequest)WebRequest.Create(url);
webRequest.ProtocolVersion = HttpVersion.Version10;
webRequest.Method = "POST";
webRequest.ContentType = "text/xml charset=utf8";
webRequest.ContentLength = postData.Length;
Stream requestStream = webRequest.GetRequestStream();
requestStream.Write(postData, 0, postData.Length);
requestStream.Close();
HttpWebResponse webResponse = (HttpWebResponse)webRequest.GetResponse();
StreamReader reader = new StreamReader(webResponse.GetResponseStream());
string reader2 = reader.ReadToEnd();
List<XmlData> ObjXmlData = new List<XmlData>();
XDocument doc = XDocument.Parse(reader2);

// How Can I bind it to the listview


My Data Model



 public class XmlData

public string TransactionId get; set;
public string Question get; set;
public string Answer get; set;



My List View



 <ListView x:Name="QuestionsListView" ItemsSource="Binding"
HasUnevenRows="True"
HorizontalOptions="FillAndExpand"
VerticalOptions="FillAndExpand">
<ListView.ItemTemplate>
<DataTemplate>
<ViewCell>
<ViewCell.View>
<StackLayout>
<StackLayout Orientation="Horizontal">
<Label Text="•" FontSize="Medium" TextColor="Green" Margin="0,20,0,0"/>
<Label Text="Binding Question" FontSize="Small" TextColor="#474747" Margin="0,20,0,0">
</Label>
</StackLayout>
<StackLayout Orientation="Horizontal" Margin="10,0,10,0" HorizontalOptions="FillAndExpand" >
<Picker x:Name="picker1" Title="Select answer" ItemDisplayBinding="Binding Answer" HorizontalOptions="FillAndExpand" FontSize="Small" TextColor="Gray">
</Picker>
<Image Source="downarrow.png" HorizontalOptions="End" HeightRequest="20" WidthRequest="20" ></Image>
</StackLayout>
</StackLayout>
</ViewCell.View>
</ViewCell>
</DataTemplate>
</ListView.ItemTemplate>
</ListView

>


How Can I bind these questions and answers to picker and label. Any help appreciated.










share|improve this question


























  • 1) Do you want to flatten your XDocument to your model? OR 2) Do you want to bind your model to list view?

    – er-sho
    Mar 28 at 5:54











  • @er-sho I want to parse the xml and bind it to my listview

    – AndroDevil
    Mar 28 at 5:57











  • @er-sho where iam stuck is creating a view model according to the xml and binding to the listview after parse

    – AndroDevil
    Mar 28 at 5:58











  • means you have 2 question in same post, could you please edit your post and ask these 2 question in different post. otherwise most likely your post has been marked as to broad by users.

    – er-sho
    Mar 28 at 6:18











  • @er-sho Bro sorry. My question is How can I make the xml to bind to the listview.Iam stuck at creating the data model

    – AndroDevil
    Mar 28 at 6:21













0












0








0








Hi I am trying to parse XML in my xamarin.forms app.The xml data contains one transactionID and couple of questions with multiple answers. What Iam trying to achieve is Bind the questions in to label and and answers into dropdowns in a listview.



The XML Iam getting from API



<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<PlatformResponse>
<TransactionDetails>
<TransactId>39562</TransactionId>
</TransactionDetails>
<Response>
<Questions>
<Question type="1" text="Which one is correct?">
<Answer correct="false">test1</Answer>
<Answer correct="false">test2</Answer>
<Answer correct="false">test3</Answer>
<Answer correct="false">test4</Answer>
<Answer correct="false">test5</Answer>
<Answer correct="false">test5</Answer>
</Question>
<Question type="2" text="Which one is associated with you?">
<Answer correct="false">test1</Answer>
<Answer correct="false">test2</Answer>
<Answer correct="false">test3</Answer>
<Answer correct="false">test4</Answer>
<Answer correct="false">test5</Answer>
<Answer correct="false">test5</Answer>
</Question>
<Question type="3" text="Which one of the following is true ?">
<Answer correct="false">test1</Answer>
<Answer correct="false">test2</Answer>
<Answer correct="false">test3</Answer>
<Answer correct="false">test4</Answer>
<Answer correct="false">test5</Answer>
<Answer correct="false">test5</Answer>
</Question>
</Questions>
</Response>
</PlatformResponse>


How Iam parsing it



 HttpWebRequest webRequest = (HttpWebRequest)WebRequest.Create(url);
webRequest.ProtocolVersion = HttpVersion.Version10;
webRequest.Method = "POST";
webRequest.ContentType = "text/xml charset=utf8";
webRequest.ContentLength = postData.Length;
Stream requestStream = webRequest.GetRequestStream();
requestStream.Write(postData, 0, postData.Length);
requestStream.Close();
HttpWebResponse webResponse = (HttpWebResponse)webRequest.GetResponse();
StreamReader reader = new StreamReader(webResponse.GetResponseStream());
string reader2 = reader.ReadToEnd();
List<XmlData> ObjXmlData = new List<XmlData>();
XDocument doc = XDocument.Parse(reader2);

// How Can I bind it to the listview


My Data Model



 public class XmlData

public string TransactionId get; set;
public string Question get; set;
public string Answer get; set;



My List View



 <ListView x:Name="QuestionsListView" ItemsSource="Binding"
HasUnevenRows="True"
HorizontalOptions="FillAndExpand"
VerticalOptions="FillAndExpand">
<ListView.ItemTemplate>
<DataTemplate>
<ViewCell>
<ViewCell.View>
<StackLayout>
<StackLayout Orientation="Horizontal">
<Label Text="•" FontSize="Medium" TextColor="Green" Margin="0,20,0,0"/>
<Label Text="Binding Question" FontSize="Small" TextColor="#474747" Margin="0,20,0,0">
</Label>
</StackLayout>
<StackLayout Orientation="Horizontal" Margin="10,0,10,0" HorizontalOptions="FillAndExpand" >
<Picker x:Name="picker1" Title="Select answer" ItemDisplayBinding="Binding Answer" HorizontalOptions="FillAndExpand" FontSize="Small" TextColor="Gray">
</Picker>
<Image Source="downarrow.png" HorizontalOptions="End" HeightRequest="20" WidthRequest="20" ></Image>
</StackLayout>
</StackLayout>
</ViewCell.View>
</ViewCell>
</DataTemplate>
</ListView.ItemTemplate>
</ListView

>


How Can I bind these questions and answers to picker and label. Any help appreciated.










share|improve this question
















Hi I am trying to parse XML in my xamarin.forms app.The xml data contains one transactionID and couple of questions with multiple answers. What Iam trying to achieve is Bind the questions in to label and and answers into dropdowns in a listview.



The XML Iam getting from API



<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<PlatformResponse>
<TransactionDetails>
<TransactId>39562</TransactionId>
</TransactionDetails>
<Response>
<Questions>
<Question type="1" text="Which one is correct?">
<Answer correct="false">test1</Answer>
<Answer correct="false">test2</Answer>
<Answer correct="false">test3</Answer>
<Answer correct="false">test4</Answer>
<Answer correct="false">test5</Answer>
<Answer correct="false">test5</Answer>
</Question>
<Question type="2" text="Which one is associated with you?">
<Answer correct="false">test1</Answer>
<Answer correct="false">test2</Answer>
<Answer correct="false">test3</Answer>
<Answer correct="false">test4</Answer>
<Answer correct="false">test5</Answer>
<Answer correct="false">test5</Answer>
</Question>
<Question type="3" text="Which one of the following is true ?">
<Answer correct="false">test1</Answer>
<Answer correct="false">test2</Answer>
<Answer correct="false">test3</Answer>
<Answer correct="false">test4</Answer>
<Answer correct="false">test5</Answer>
<Answer correct="false">test5</Answer>
</Question>
</Questions>
</Response>
</PlatformResponse>


How Iam parsing it



 HttpWebRequest webRequest = (HttpWebRequest)WebRequest.Create(url);
webRequest.ProtocolVersion = HttpVersion.Version10;
webRequest.Method = "POST";
webRequest.ContentType = "text/xml charset=utf8";
webRequest.ContentLength = postData.Length;
Stream requestStream = webRequest.GetRequestStream();
requestStream.Write(postData, 0, postData.Length);
requestStream.Close();
HttpWebResponse webResponse = (HttpWebResponse)webRequest.GetResponse();
StreamReader reader = new StreamReader(webResponse.GetResponseStream());
string reader2 = reader.ReadToEnd();
List<XmlData> ObjXmlData = new List<XmlData>();
XDocument doc = XDocument.Parse(reader2);

// How Can I bind it to the listview


My Data Model



 public class XmlData

public string TransactionId get; set;
public string Question get; set;
public string Answer get; set;



My List View



 <ListView x:Name="QuestionsListView" ItemsSource="Binding"
HasUnevenRows="True"
HorizontalOptions="FillAndExpand"
VerticalOptions="FillAndExpand">
<ListView.ItemTemplate>
<DataTemplate>
<ViewCell>
<ViewCell.View>
<StackLayout>
<StackLayout Orientation="Horizontal">
<Label Text="•" FontSize="Medium" TextColor="Green" Margin="0,20,0,0"/>
<Label Text="Binding Question" FontSize="Small" TextColor="#474747" Margin="0,20,0,0">
</Label>
</StackLayout>
<StackLayout Orientation="Horizontal" Margin="10,0,10,0" HorizontalOptions="FillAndExpand" >
<Picker x:Name="picker1" Title="Select answer" ItemDisplayBinding="Binding Answer" HorizontalOptions="FillAndExpand" FontSize="Small" TextColor="Gray">
</Picker>
<Image Source="downarrow.png" HorizontalOptions="End" HeightRequest="20" WidthRequest="20" ></Image>
</StackLayout>
</StackLayout>
</ViewCell.View>
</ViewCell>
</DataTemplate>
</ListView.ItemTemplate>
</ListView

>


How Can I bind these questions and answers to picker and label. Any help appreciated.







c# xml xamarin.forms






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Mar 28 at 5:18







AndroDevil

















asked Mar 28 at 5:11









AndroDevilAndroDevil

5316 silver badges16 bronze badges




5316 silver badges16 bronze badges















  • 1) Do you want to flatten your XDocument to your model? OR 2) Do you want to bind your model to list view?

    – er-sho
    Mar 28 at 5:54











  • @er-sho I want to parse the xml and bind it to my listview

    – AndroDevil
    Mar 28 at 5:57











  • @er-sho where iam stuck is creating a view model according to the xml and binding to the listview after parse

    – AndroDevil
    Mar 28 at 5:58











  • means you have 2 question in same post, could you please edit your post and ask these 2 question in different post. otherwise most likely your post has been marked as to broad by users.

    – er-sho
    Mar 28 at 6:18











  • @er-sho Bro sorry. My question is How can I make the xml to bind to the listview.Iam stuck at creating the data model

    – AndroDevil
    Mar 28 at 6:21

















  • 1) Do you want to flatten your XDocument to your model? OR 2) Do you want to bind your model to list view?

    – er-sho
    Mar 28 at 5:54











  • @er-sho I want to parse the xml and bind it to my listview

    – AndroDevil
    Mar 28 at 5:57











  • @er-sho where iam stuck is creating a view model according to the xml and binding to the listview after parse

    – AndroDevil
    Mar 28 at 5:58











  • means you have 2 question in same post, could you please edit your post and ask these 2 question in different post. otherwise most likely your post has been marked as to broad by users.

    – er-sho
    Mar 28 at 6:18











  • @er-sho Bro sorry. My question is How can I make the xml to bind to the listview.Iam stuck at creating the data model

    – AndroDevil
    Mar 28 at 6:21
















1) Do you want to flatten your XDocument to your model? OR 2) Do you want to bind your model to list view?

– er-sho
Mar 28 at 5:54





1) Do you want to flatten your XDocument to your model? OR 2) Do you want to bind your model to list view?

– er-sho
Mar 28 at 5:54













@er-sho I want to parse the xml and bind it to my listview

– AndroDevil
Mar 28 at 5:57





@er-sho I want to parse the xml and bind it to my listview

– AndroDevil
Mar 28 at 5:57













@er-sho where iam stuck is creating a view model according to the xml and binding to the listview after parse

– AndroDevil
Mar 28 at 5:58





@er-sho where iam stuck is creating a view model according to the xml and binding to the listview after parse

– AndroDevil
Mar 28 at 5:58













means you have 2 question in same post, could you please edit your post and ask these 2 question in different post. otherwise most likely your post has been marked as to broad by users.

– er-sho
Mar 28 at 6:18





means you have 2 question in same post, could you please edit your post and ask these 2 question in different post. otherwise most likely your post has been marked as to broad by users.

– er-sho
Mar 28 at 6:18













@er-sho Bro sorry. My question is How can I make the xml to bind to the listview.Iam stuck at creating the data model

– AndroDevil
Mar 28 at 6:21





@er-sho Bro sorry. My question is How can I make the xml to bind to the listview.Iam stuck at creating the data model

– AndroDevil
Mar 28 at 6:21












1 Answer
1






active

oldest

votes


















1
















1) For your first question,



Below are the class models to parse your xml,



class Answer

public string Text get; set;
public bool Correct get; set;


class Question

public string Ques get; set;
public string Type get; set;
public List<Answer> Answers get; set;


class Tranzaction

public string TransactionId get; set;
public List<Question> Questions get; set;



And by using LINQ to XML you can parse your xml to above class models like,



XDocument doc = XDocument.Parse("Your xml text here");

List<Tranzaction> transactions = (from p in doc.Descendants("PlatformResponse")
select new Tranzaction

TransactionId = p?.Elements("TransactionDetails")?.FirstOrDefault()?.Element("TransactionId")?.Value.Trim(),
Questions = (from q in p?.Descendants("Questions")?.Elements("Question")
select new Question

Ques = q?.Attribute("text")?.Value,
Type = q?.Attribute("type")?.Value,
Answers = (from a in q?.Elements("Answer")
select new Answer

Text = a?.Value,
Correct = Convert.ToBoolean(a?.Attribute("correct")?.Value)
).ToList()
).ToList()

).ToList();


2) For your second question,



Now you can create one ObservableCollection for above query result and bind it to list view in your xamarin form like



ObservableCollection<Tranzaction> tranzactionsOC = new ObservableCollection<Tranzaction>(transactions);


Now tranzactionsOC is your ObservableCollection and you can bind it to your xamarin form






share|improve this answer



























  • let me check bro

    – AndroDevil
    Mar 28 at 8:04











  • @Bro sorry for disturbing. Is my xaml bindings are correct?

    – AndroDevil
    Mar 28 at 8:13











  • @AndroDevil, Remember ?. is use for null checking and introduced in c# 6. If it gives you error on your side then simply remove it

    – er-sho
    Mar 28 at 8:13











  • @AndroDevil, not sure about xaml binding, because I mostly work on XML and Web API so its hard to say that, but you can find some way if you google it. Up to I'll consult with my xamarin collegues for any solution.

    – er-sho
    Mar 28 at 8:16











  • @AndroDevil, but above observable collection is most probably includes all your data in xml and I think you should use it.

    – er-sho
    Mar 28 at 8:17










Your Answer






StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");

StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/4.0/"u003ecc by-sa 4.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);














draft saved

draft discarded
















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55390579%2fxml-parse-and-binding-to-listview-on-xamarin-forms%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









1
















1) For your first question,



Below are the class models to parse your xml,



class Answer

public string Text get; set;
public bool Correct get; set;


class Question

public string Ques get; set;
public string Type get; set;
public List<Answer> Answers get; set;


class Tranzaction

public string TransactionId get; set;
public List<Question> Questions get; set;



And by using LINQ to XML you can parse your xml to above class models like,



XDocument doc = XDocument.Parse("Your xml text here");

List<Tranzaction> transactions = (from p in doc.Descendants("PlatformResponse")
select new Tranzaction

TransactionId = p?.Elements("TransactionDetails")?.FirstOrDefault()?.Element("TransactionId")?.Value.Trim(),
Questions = (from q in p?.Descendants("Questions")?.Elements("Question")
select new Question

Ques = q?.Attribute("text")?.Value,
Type = q?.Attribute("type")?.Value,
Answers = (from a in q?.Elements("Answer")
select new Answer

Text = a?.Value,
Correct = Convert.ToBoolean(a?.Attribute("correct")?.Value)
).ToList()
).ToList()

).ToList();


2) For your second question,



Now you can create one ObservableCollection for above query result and bind it to list view in your xamarin form like



ObservableCollection<Tranzaction> tranzactionsOC = new ObservableCollection<Tranzaction>(transactions);


Now tranzactionsOC is your ObservableCollection and you can bind it to your xamarin form






share|improve this answer



























  • let me check bro

    – AndroDevil
    Mar 28 at 8:04











  • @Bro sorry for disturbing. Is my xaml bindings are correct?

    – AndroDevil
    Mar 28 at 8:13











  • @AndroDevil, Remember ?. is use for null checking and introduced in c# 6. If it gives you error on your side then simply remove it

    – er-sho
    Mar 28 at 8:13











  • @AndroDevil, not sure about xaml binding, because I mostly work on XML and Web API so its hard to say that, but you can find some way if you google it. Up to I'll consult with my xamarin collegues for any solution.

    – er-sho
    Mar 28 at 8:16











  • @AndroDevil, but above observable collection is most probably includes all your data in xml and I think you should use it.

    – er-sho
    Mar 28 at 8:17















1
















1) For your first question,



Below are the class models to parse your xml,



class Answer

public string Text get; set;
public bool Correct get; set;


class Question

public string Ques get; set;
public string Type get; set;
public List<Answer> Answers get; set;


class Tranzaction

public string TransactionId get; set;
public List<Question> Questions get; set;



And by using LINQ to XML you can parse your xml to above class models like,



XDocument doc = XDocument.Parse("Your xml text here");

List<Tranzaction> transactions = (from p in doc.Descendants("PlatformResponse")
select new Tranzaction

TransactionId = p?.Elements("TransactionDetails")?.FirstOrDefault()?.Element("TransactionId")?.Value.Trim(),
Questions = (from q in p?.Descendants("Questions")?.Elements("Question")
select new Question

Ques = q?.Attribute("text")?.Value,
Type = q?.Attribute("type")?.Value,
Answers = (from a in q?.Elements("Answer")
select new Answer

Text = a?.Value,
Correct = Convert.ToBoolean(a?.Attribute("correct")?.Value)
).ToList()
).ToList()

).ToList();


2) For your second question,



Now you can create one ObservableCollection for above query result and bind it to list view in your xamarin form like



ObservableCollection<Tranzaction> tranzactionsOC = new ObservableCollection<Tranzaction>(transactions);


Now tranzactionsOC is your ObservableCollection and you can bind it to your xamarin form






share|improve this answer



























  • let me check bro

    – AndroDevil
    Mar 28 at 8:04











  • @Bro sorry for disturbing. Is my xaml bindings are correct?

    – AndroDevil
    Mar 28 at 8:13











  • @AndroDevil, Remember ?. is use for null checking and introduced in c# 6. If it gives you error on your side then simply remove it

    – er-sho
    Mar 28 at 8:13











  • @AndroDevil, not sure about xaml binding, because I mostly work on XML and Web API so its hard to say that, but you can find some way if you google it. Up to I'll consult with my xamarin collegues for any solution.

    – er-sho
    Mar 28 at 8:16











  • @AndroDevil, but above observable collection is most probably includes all your data in xml and I think you should use it.

    – er-sho
    Mar 28 at 8:17













1














1










1









1) For your first question,



Below are the class models to parse your xml,



class Answer

public string Text get; set;
public bool Correct get; set;


class Question

public string Ques get; set;
public string Type get; set;
public List<Answer> Answers get; set;


class Tranzaction

public string TransactionId get; set;
public List<Question> Questions get; set;



And by using LINQ to XML you can parse your xml to above class models like,



XDocument doc = XDocument.Parse("Your xml text here");

List<Tranzaction> transactions = (from p in doc.Descendants("PlatformResponse")
select new Tranzaction

TransactionId = p?.Elements("TransactionDetails")?.FirstOrDefault()?.Element("TransactionId")?.Value.Trim(),
Questions = (from q in p?.Descendants("Questions")?.Elements("Question")
select new Question

Ques = q?.Attribute("text")?.Value,
Type = q?.Attribute("type")?.Value,
Answers = (from a in q?.Elements("Answer")
select new Answer

Text = a?.Value,
Correct = Convert.ToBoolean(a?.Attribute("correct")?.Value)
).ToList()
).ToList()

).ToList();


2) For your second question,



Now you can create one ObservableCollection for above query result and bind it to list view in your xamarin form like



ObservableCollection<Tranzaction> tranzactionsOC = new ObservableCollection<Tranzaction>(transactions);


Now tranzactionsOC is your ObservableCollection and you can bind it to your xamarin form






share|improve this answer















1) For your first question,



Below are the class models to parse your xml,



class Answer

public string Text get; set;
public bool Correct get; set;


class Question

public string Ques get; set;
public string Type get; set;
public List<Answer> Answers get; set;


class Tranzaction

public string TransactionId get; set;
public List<Question> Questions get; set;



And by using LINQ to XML you can parse your xml to above class models like,



XDocument doc = XDocument.Parse("Your xml text here");

List<Tranzaction> transactions = (from p in doc.Descendants("PlatformResponse")
select new Tranzaction

TransactionId = p?.Elements("TransactionDetails")?.FirstOrDefault()?.Element("TransactionId")?.Value.Trim(),
Questions = (from q in p?.Descendants("Questions")?.Elements("Question")
select new Question

Ques = q?.Attribute("text")?.Value,
Type = q?.Attribute("type")?.Value,
Answers = (from a in q?.Elements("Answer")
select new Answer

Text = a?.Value,
Correct = Convert.ToBoolean(a?.Attribute("correct")?.Value)
).ToList()
).ToList()

).ToList();


2) For your second question,



Now you can create one ObservableCollection for above query result and bind it to list view in your xamarin form like



ObservableCollection<Tranzaction> tranzactionsOC = new ObservableCollection<Tranzaction>(transactions);


Now tranzactionsOC is your ObservableCollection and you can bind it to your xamarin form







share|improve this answer














share|improve this answer



share|improve this answer








edited Mar 28 at 8:04

























answered Mar 28 at 8:03









er-shoer-sho

7,9282 gold badges6 silver badges19 bronze badges




7,9282 gold badges6 silver badges19 bronze badges















  • let me check bro

    – AndroDevil
    Mar 28 at 8:04











  • @Bro sorry for disturbing. Is my xaml bindings are correct?

    – AndroDevil
    Mar 28 at 8:13











  • @AndroDevil, Remember ?. is use for null checking and introduced in c# 6. If it gives you error on your side then simply remove it

    – er-sho
    Mar 28 at 8:13











  • @AndroDevil, not sure about xaml binding, because I mostly work on XML and Web API so its hard to say that, but you can find some way if you google it. Up to I'll consult with my xamarin collegues for any solution.

    – er-sho
    Mar 28 at 8:16











  • @AndroDevil, but above observable collection is most probably includes all your data in xml and I think you should use it.

    – er-sho
    Mar 28 at 8:17

















  • let me check bro

    – AndroDevil
    Mar 28 at 8:04











  • @Bro sorry for disturbing. Is my xaml bindings are correct?

    – AndroDevil
    Mar 28 at 8:13











  • @AndroDevil, Remember ?. is use for null checking and introduced in c# 6. If it gives you error on your side then simply remove it

    – er-sho
    Mar 28 at 8:13











  • @AndroDevil, not sure about xaml binding, because I mostly work on XML and Web API so its hard to say that, but you can find some way if you google it. Up to I'll consult with my xamarin collegues for any solution.

    – er-sho
    Mar 28 at 8:16











  • @AndroDevil, but above observable collection is most probably includes all your data in xml and I think you should use it.

    – er-sho
    Mar 28 at 8:17
















let me check bro

– AndroDevil
Mar 28 at 8:04





let me check bro

– AndroDevil
Mar 28 at 8:04













@Bro sorry for disturbing. Is my xaml bindings are correct?

– AndroDevil
Mar 28 at 8:13





@Bro sorry for disturbing. Is my xaml bindings are correct?

– AndroDevil
Mar 28 at 8:13













@AndroDevil, Remember ?. is use for null checking and introduced in c# 6. If it gives you error on your side then simply remove it

– er-sho
Mar 28 at 8:13





@AndroDevil, Remember ?. is use for null checking and introduced in c# 6. If it gives you error on your side then simply remove it

– er-sho
Mar 28 at 8:13













@AndroDevil, not sure about xaml binding, because I mostly work on XML and Web API so its hard to say that, but you can find some way if you google it. Up to I'll consult with my xamarin collegues for any solution.

– er-sho
Mar 28 at 8:16





@AndroDevil, not sure about xaml binding, because I mostly work on XML and Web API so its hard to say that, but you can find some way if you google it. Up to I'll consult with my xamarin collegues for any solution.

– er-sho
Mar 28 at 8:16













@AndroDevil, but above observable collection is most probably includes all your data in xml and I think you should use it.

– er-sho
Mar 28 at 8:17





@AndroDevil, but above observable collection is most probably includes all your data in xml and I think you should use it.

– er-sho
Mar 28 at 8:17








Got a question that you can’t ask on public Stack Overflow? Learn more about sharing private information with Stack Overflow for Teams.







Got a question that you can’t ask on public Stack Overflow? Learn more about sharing private information with Stack Overflow for Teams.




















draft saved

draft discarded















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55390579%2fxml-parse-and-binding-to-listview-on-xamarin-forms%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

Swift 4 - func physicsWorld not invoked on collision? The Next CEO of Stack OverflowHow to call Objective-C code from Swift#ifdef replacement in the Swift language@selector() in Swift?#pragma mark in Swift?Swift for loop: for index, element in array?dispatch_after - GCD in Swift?Swift Beta performance: sorting arraysSplit a String into an array in Swift?The use of Swift 3 @objc inference in Swift 4 mode is deprecated?How to optimize UITableViewCell, because my UITableView lags

Access current req object everywhere in Node.js ExpressWhy are global variables considered bad practice? (node.js)Using req & res across functionsHow do I get the path to the current script with Node.js?What is Node.js' Connect, Express and “middleware”?Node.js w/ express error handling in callbackHow to access the GET parameters after “?” in Express?Modify Node.js req object parametersAccess “app” variable inside of ExpressJS/ConnectJS middleware?Node.js Express app - request objectAngular Http Module considered middleware?Session variables in ExpressJSAdd properties to the req object in expressjs with Typescript