Hi, I have a xml which is max 3 levels deep. Now by using C# or Xpath what the best method to check the whether all the child nodes under a parent node are empty.
Thanks in Advance.
Hi, I have a xml which is max 3 levels deep. Now by using C# or Xpath what the best method to check the whether all the child nodes under a parent node are empty.
Thanks in Advance.
Given a sample document of:
<foo>
<bar>
<baz/>
<baz>Hello, world!</baz>
<baz><qux/></baz>
</bar>
</foo>
This expression tells you which children of foo/bar
have any child elements:
foo/bar/*[count(*)>0]
This expression tells you which children of foo/bar
have any child text nodes:
foo/bar/*[text()]
So to ensure that all children are empty (no child elements or text nodes), ensure that this expression returns true:
not(foo/bar/*[count(*)>0 or text()])