You need to parse the XML in such a way as to capture all the data / subtags for a given single tag. For example:

<root> <Response> <Data> <Item>something</Item> <Number>1</Number> </Data> <Data> <Item>book</Item> <Number>2</Number> </Data> </Response> </root> 

The task is to select the following XML fragment according to a given tag, in this case Response:

 <Response> <Data> <Item>something</Item> <Number>1</Number> </Data> <Data> <Item>book</Item> <Number>2</Number> </Data> </Response> 

    2 answers 2

    An example of getting a NodeList by tag:

     Document doc = null; try { DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); DocumentBuilder db = dbf.newDocumentBuilder(); File f = new File("NewFile.xml"); doc = db.parse(f); } catch (Exception e) { System.out.println(e); } NodeList nodes = doc.getElementsByTagName("Response"); 

    nodes-list of elements "Response". You can get a Node element from this list by index.

      You should not follow the example of comrade @Peter Slusar (you will forgive, but use the standard hml parser at the moment moveton). We use jdom2 api:

       fro (Element element : doc.getRootElement.elements("Response")) { //тело с парсингом параметров }