Sie können XDocument verwenden
string xml = ""; /* your xml */
XDocument xDocument = XDocument.Parse(xml);
foreach(XElement questionElement in xDocument.Root.Elements("question"))
{
foreach(XElement optionElement in questionElement.Elements("option"))
{
string text = optionElement.Element("text").Value;
string value = optionElement.Element("value").Value;
/* do something with them here */
}
}
das Attribut id Mit allen Auswahlboxen zu binden:
string xml = ""; /* your xml */
XDocument xDocument = XDocument.Parse(xml);
foreach(XElement questionElement in xDocument.Root.Elements("question"))
{
string id = questionElement.Attribute("id").Value;
foreach(XElement optionElement in questionElement.Elements("option"))
{
string text = optionElement.Element("text").Value;
string value = optionElement.Element("value").Value;
/* bind selectbox options here, using id,text,value */
}
}
id Mit einer Auswahlbox zu binden:
string id = "title";
string xml = ""; /* your xml */
XDocument xDocument = XDocument.Parse(xml);
XElement questionElement = xDocument.Root.Elements("question").SingleOrDefault(e => e.Attribute("id").Value == "title");
if (questionElement != null)
{
foreach(XElement optionElement in questionElement.Elements("option"))
{
string text = optionElement.Element("text").Value;
string value = optionElement.Element("value").Value;
/* bind selectbox options here, using id,text,value */
}
}
das Format der XML ist nicht festgelegt. Gibt es ein anderes Format, das die XSL-Transformation nicht benötigt? – user
Ja, das ist das Ergebnis der XSL-Transformation. Wenn es nicht behoben ist, müssen Sie es reparieren oder Sie können es nicht verwenden. Eine andere Möglichkeit wäre, diese XSL-Datei dynamisch zu generieren, basierend auf der Syntax Ihrer XML-Datei, aber ich würde Ihnen wirklich empfehlen, sie zu normalisieren. –
ok so was wäre der XPath nur die Werte unter entsprechen: Frage ID = "Titel" – user