Question:
You create a Microsoft ASP.NET application by using the Microsoft .NET Framework version 3.5. You store the following XML fragment in a string variable named xmlFragment in a Web form.

<Products>
<Product price="12" />
<Product price="24" />
<Product price="56" />
<Product price="89" />
</Products>

You need to display the value of the price attribute for each Product element that is contained in a ListBox control named lstPrices. Which code segment should you use? 

A XElement element = XElement.Parse(xmlFragment);
var lst = from prods in element.Elements("Product") select prods.Attribute("price").Value; lstPrices.DataSource = lst; lstPrices.DataBind(); 

B var doc = new XmlDocument(); doc.LoadXml(xmlFragment);
foreach (XmlNode price in doc.SelectNodes("//price")) {
lstPrices.Items.Add(price.ToString()); } 

C var reader = new XmlTextReader(new StringReader(xmlFragment));
XNode node = XElement.ReadFrom(reader);
var lst = from prods in node.ElementsAfterSelf("Product") select prods.Attribute("price").Value;
lstPrices.DataSource = lst; lstPrices.DataBind(); 

D var doc = new XmlDocument();
doc.LoadXml(xmlFragment);
foreach (XmlNode price in doc.SelectNodes("Products/price")) {
lstPrices.Items.Add(price.Value); } 

+ Answer
+ Report
Total Preview: 1726

Copyright © 2024. Powered by Intellect Software Ltd