Das serialisieren von xml-Daten in gewünschtes format in asp.net web-api

Arbeite ich auf asp.net mvc 4 web api. Ich habe eine Klasse wie,

public class Quiz
{
public int QuizId{get; set;}
public string title{get; set;}
...
...
}

bin ich jetzt beim abrufen der Liste der quizs, also schrieb ich wie,

public List<Quiz> GetQuizs()
{
return repository.ListQuizs();
}

brauche ich xml-Antwort so habe ich mir vorgenommen-Konfiguration in webapi.config-Datei wie

config.Formatters.XmlFormatter.UseXmlSerializer = true;

und ich bekam eine Antwort wie,

<ArrayOfQuiz xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<Quiz>
<QuizId>4</QuizId>
<title>Master Minds</title>
</Quiz>
<Quiz>
<QuizId>5</QuizId>
<title>Master Minds</title>
</Quiz>
</ArrayOfQuiz>

aber ich möchte die Antwort gerne

<Quizs>
<Quiz>
<QuizId>4</QuizId>
<title>Master Minds</title>
</Quiz>
<Quiz>
<QuizId>5</QuizId>
<title>Master Minds</title>
</Quiz>
</Quiz>

habe ich versucht wie,

public class quizs:List<Quiz>{}
public class Quiz
{
//properties here
}

aber ich bin nicht in der Lage zu laden, Liste von quizs in quizs Klasse. bitte führe mich.

InformationsquelleAutor Karthik Bammidi | 2012-12-06

Schreibe einen Kommentar