I want to extract every Area between <xsd:headerName>
and </xsd:headerName>
. Since I write a code generator I can't define how often it is present because it can be different with every xml.
I just get null pointers when executing so what do I do wrong?
Without the list I get the first area but I need all of them separately.
String xmlToString = null;
List<String> ComplexTypeList = null;
String path = "/path/of/xml";
try {
xmlToString = FileUtils.readFileToString(new File(path), StandardCharsets.UTF_8);
} catch (IOException e) {
e.printStackTrace();
}
for (int i = 0; i < headerName.size(); i++) {
String result = xmlToString.substring(xmlToString.indexOf("<xsd:headerName"), xmlToString.indexOf("</xsd:headerName>") + 18); // +18 so i get </xsd:headerName>
ComplexTypeList.add(result); // here i get a Nullpointer
}
EDIT: So now that it almost works I still have the problem that he always takes the same / first area. How can I solve this so that he always jumps to the next one?