Answer the question
In order to leave comments, you need to log in
C# XML How to check if a node exists?
Hello! I can not find on the Internet how to check the existence of a node?
<head>
<block1></block1>
<block2></block2>
<block3></block3>
</head>
Answer the question
In order to leave comments, you need to log in
using System.Xml;
var xml = @"<head>
<block1></block1>
<block2></block2>
<block3></block3>
</head>";
var doc = new XmlDocument();
doc.LoadXml(xml);
var node = doc.SelectSingleNode("/head/block3");
if (node != null)
{
Console.WriteLine("Узел существует!");
}
else
{
Console.WriteLine("Узел не найден...");
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question