is there a GetElementByTagName that handles if the tag isn't there
Posted
by oo
on Stack Overflow
See other posts from Stack Overflow
or by oo
Published on 2010-04-25T05:28:51Z
Indexed on
2010/04/25
5:33 UTC
Read the original article
Hit count: 175
i have the following code below but sometime the "serving_description" tag isn't there. Right now i just put a try catch around it but i wanted to find out if there was a cleaner way to handle this scenario.
XmlElement servingElement = (XmlElement)servingNode;
serving.Id = Convert.ToInt32(servingElement.GetElementsByTagName("serving_id")[0].InnerText);
serving.Name = servingElement.GetElementsByTagName("serving_description")[0].InnerText;
© Stack Overflow or respective owner