Select from following answers:- string city = doc.FirstChild.FirstChild.SelectSingleNode("address").Attributes["city"].Value

- string city = doc.FirstChild.FirstChild.SelectSingleNode("address"). SelectSingleNode("city").Value;
- string city = doc.FirstChild.Attributes["address"].SelectSingleNode("city").Value;
- All Above
In this example, doc.FirstChild refers to the customers element. To select the first customer element, you must refer to doc.FirstChild.FirstChild. To select the city, you must then call SelectSingleNode("address").Attributes["city"]. SelectSingleNode is used to reference all nodes such as address.
This example throws an exception. FirstChild called once refers to the customers element, not the address element. Further, this code searches for an element named city, not an attribute:
string city = doc.FirstChild.SelectSingleNode("address").Attributes["city"].Value;
Show Correct Answer
Source: MeasureUp.Com | |
Alert Moderator