[英]Displaying xml item in a listbox (XlmSerialiser)
I have the following deserialize method: 我有以下反序列化方法:
public static List<Enquete> GetAlleEnquetes()
{
XmlReader reader = new XmlTextReader(HttpContext.Current.Server.MapPath("~/App_Data/Questions.xml"));
try
{
XmlSerializer serializer = new XmlSerializer(typeof(List<Enquete>), new XmlRootAttribute("enqueteSysteem"));
return (List<Enquete>)(serializer.Deserialize(reader));
}
finally
{
reader.Close();
}
}
public static Enquete GetEnqueteName(string name)
{
foreach (Enquete e in GetAllEnquetes())
{
if (e.Name == name)
return e;
}
return null;
}
Which works properly (this code is located in a class withing App_data). 哪个可以正常工作(此代码位于带有App_data的类中)。
Next i want to retrieve all the names and display them in a listbox. 接下来,我想检索所有名称并将它们显示在列表框中。
But how exactly do i retrieve the names? 但是我该如何准确检索名称?
<Enquete Name ="">
and list all of those in my listbox control? <Enquete Name ="">
并列出我的列表框控件中的所有内容? (through the asp.cs file) (通过asp.cs文件)
My xml structure looks like this: 我的xml结构如下所示:
<enqueteSystem xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<Enquete Name="test">
<Questions>
<Question QuestionText="testtest" QuestionType="na"></Question>
</Questions>
</Enquete>
</enqueteSystem>
to retrieve all the names 检索所有名称
var serializedEnquetes = XDocument.Parse(serializedXml);
IEnumerable<string> names = serializedEnquetes
.Descendants("Enquete")
.Attributes("Name")
.Select(a => a.Value);
Then simply use the 'names' collection as a source for your listbox 然后只需将“名称”集合用作列表框的来源
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.