I have a XML file, I'm reading it's content using BufferedReader, i then store some pieces of information in String using substring. See following code:
Load file, basically I take whole xml file and store it in String called whole XML
try {
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(new FileInputStream(inputFile), "UTF-8"));
while ((line2 = bufferedReader.readLine()) != null) {
wholeXML= line2;
} catch (IOException ex2) {
System.out.println("Exception xml");
}
after that i use substring to get data i need for example:
String senderID = wholeXML.substring(wholeXML.indexOf("<q1:SenderID>")+13,wholeXML.indexOf("</q1:SenderID>"));`
This serves my purpose and workes just fine, but i'm having problem because one part in xml file is not static it's dynamic, like this:
q1:Attachment>
<q1:AttachmentID>ba9727cc-a831-4ded-b88c-a00000041357</q1:AttachmentID>
</q1:Attachment>
-<q1:Attachment>
<q1:AttachmentID>c0773e77-e011-484e-a1e9-b00000131099</q1:AttachmentID>
</q1:Attachment>
-<q1:Attachment>
<q1:AttachmentID>08f57403-2feb-443c-8dd4-b00000131103</q1:AttachmentID>
</q1:Attachment>
-<q1:Attachment>
<q1:AttachmentID>53c47aba-bb64-4349-a0dc-b00000131105</q1:AttachmentID>
</q1:Attachment>
-<q1:Attachment>
<q1:AttachmentID>3ee501ed-5c5c-43ab-8bd0-b00000131108</q1:AttachmentID>
</q1:Attachment>
-<q1:Attachment>
<q1:AttachmentID>d4fe537a-a95a-4902-a583-b00000131112</q1:AttachmentID>
So as you can see there are multiple tags with the same name and I need to store data inside of them, but I don't know how many there will be, given it's different for each XML file. I'm a beginner so please go easy on me if there is an obvious solution, I'm just not seeing it.