Scenario (minified):
<a>
<Sections>
<Section>
<Title></Title>
<Subject></Subject>
<Body></Body>
</Section>
<Section>
<Title/>
<Subject/>
<Body/>
</Section>
<Section>
<Title>Hello</Title>
<Subject></Subject>
<Body></Body>
</Section>
<Section>
<Title></Title>
<Subject>I have a problem</Subject>
<Body></Body>
</Section>
</Sections>
</a>
Question:
What XPath should I use to return a list of <Section/> nodes that have at least one child node not empty such that this is returned:
<Section>
<Title>Hello</Title>
<Subject></Subject>
<Body></Body>
</Section>
<Section>
<Title></Title>
<Subject>I have a problem</Subject>
<Body></Body>
</Section>
In other words, <Section> nodes with completely empty child nodes should be filtered out.
Try:
.//Section[./*/node()]
i.e. look for Section elements that have children that have children (text nodes or element nodes). This may or may not work depending on your requirement for empty child nodes, and may therefore need refinement.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With