How to check if a tag exists in an xml?

2
// Obtém a tag "tags"
if(xmlDoc.ChildNodes[1].ChildNodes[1].ChildNodes[1].SelectSingleNode("tags") != null)
{

}

I'm running an Xml and on some nodes there is no such tags and error tags.

Does anyone know another way to validate this?

    
asked by anonymous 29.07.2015 / 23:08

1 answer

2
var node = xmlEnvio.GetElementsByTagName("tag").OfType<XmlNode>();

if (node != null && node.Count() > 0)
{
    foreach (XmlNode item in node)
    {
        if (item["tags"] != null)
        {
            //Código
        }
    }
}

I use this form to validate nodes.

    
30.07.2015 / 16:21