Which code segment should you use?

You create a Microsoft ASP.NET application by using the Microsoft .NET Framework version 3.5.
You define the following class.

Public Class Product
Public Property Price() As Decimal
Get
Return m_Price
End Get
Set
m_Price = Value
End Set
End Property
Private m_Price As Decimal
End Class

Your application contains a Web form with a Label control named lblPrice.
You use a StringReader variable named xmlStream to access the following XML fragment.
<Product>
<Price>35</Price>
</Product>
You need to display the price of the product from the XML fragment in the lblPrice Label control.
Which code segment should you use?

You create a Microsoft ASP.NET application by using the Microsoft .NET Framework version 3.5.
You define the following class.

Public Class Product
Public Property Price() As Decimal
Get
Return m_Price
End Get
Set
m_Price = Value
End Set
End Property
Private m_Price As Decimal
End Class

Your application contains a Web form with a Label control named lblPrice.
You use a StringReader variable named xmlStream to access the following XML fragment.
<Product>
<Price>35</Price>
</Product>
You need to display the price of the product from the XML fragment in the lblPrice Label control.
Which code segment should you use?

A.
Dim dt As New DataTable()
dt.ExtendedProperties.Add("Type", "Product")
dt.ReadXml(xmlStream)
lblPrice.Text = dt.Rows(0)("Price").ToString()

B.
Dim xr As XmlReader = XmlReader.Create(xmlStream)
Dim boughtProduct As Product = TryCast(xr.ReadContentAs(GetType(Product), Nothing), Product)
lblPrice.Text = boughtProduct.Price.ToString()

C.
Dim xs As New XmlSerializer(GetType(Product))
Dim boughtProduct As Product = TryCast(xs.Deserialize(xmlStream), Product)
lblPrice.Text = boughtProduct.Price.ToString()

D.
Dim xDoc As New XmlDocument()
xDoc.Load(xmlStream)
Dim boughtProduct As Product = xDoc.OfType(Of Product)().First()
lblPrice.Text = boughtProduct.Price.ToString()



Leave a Reply 0

Your email address will not be published. Required fields are marked *