Check if XML Element exists

后端 未结 13 1624
傲寒
傲寒 2020-12-03 06:20

How can someone validate that a specific element exists in an XML file? Say I have an ever changing XML file and I need to verify every element exists before reading/parsing

13条回答
  •  一生所求
    2020-12-03 07:06

    A little bit late, but if it helps, this works for me...

    XmlNodeList NodoEstudios = DocumentoXML.SelectNodes("//ALUMNOS/ALUMNO[@id=\"" + Id + "\"]/estudios");
    
    string Proyecto = "";
    
    foreach(XmlElement ElementoProyecto in NodoEstudios)
    {
        XmlNodeList EleProyecto = ElementoProyecto.GetElementsByTagName("proyecto");
        Proyecto = (EleProyecto[0] == null)?"": EleProyecto[0].InnerText;
    }
    

提交回复
热议问题