Sax parsing with a local name of more than one kind

Is there a smart way to parse a tag found in two different areas?

@Override
public void startElement(String namespaceURI, String localName,
String qName, Attributes atts) throws SAXException {    
if (localName.equals("item")) {
       this.in_item = true;
    }
}

Example:

<xml>
   <item>
      <test1 />
      <item />
      <test2 />
   </item>
</xml>
+3
source share
3 answers

Maintain Stackpreviously seen nodes and manage our node accordingly.

+2
source

When I had the above case described, I just set the Boolean var found1item to true and, finding the next element, I checked this element and set found1item to false again. If you have a deeper investment, it can be difficult to implement, but if it is only nested, once it is simple.

+1
source

, 1- node, .

0

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


All Articles