Check if XML tag exists in Java

I am parsing XML javax.xml, but I want to know if a tag exists for a node child For example

<tag>
 <child>
  <special_tag>Special</special_tag>
  <normal_tag>Normal</normal_tag>
 </child>
 <child>
  <normal_tag>Normal</normal_tag>
 </child>
</tag>

I'm trying to find out which child has a special tag and which

+3
source share
3 answers

Using xPath:

//child[special_tag]
+1
source

Create a DOM for your xml and use XPath to query for the existence of "special_tag" with // special_tag

0
source

, SAX. . special_tag, .

0

Source: https://habr.com/ru/post/1776923/


All Articles