Source:
private List<RelationshipType> parseXMLToRelations(Context context, String fileLocation) throws AuthorizeException { try { File fXmlFile = new File(fileLocation); DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance(); DocumentBuilder dBuilder = null; dBuilder = dbFactory.newDocumentBuilder(); Document doc = dBuilder.parse(fXmlFile); doc.getDocumentElement().normalize(); NodeList nList = doc.getElementsByTagName("type"); List<RelationshipType> relationshipTypes = new LinkedList<>(); for (int i = 0; i < nList.getLength(); i++) { Node nNode = nList.item(i); if (nNode.getNodeType() == Node.ELEMENT_NODE) { Element eElement = (Element) nNode; String leftType = eElement.getElementsByTagName("leftType").item(0).getTextContent(); String rightType = eElement.getElementsByTagName("rightType").item(0).getTextContent(); String leftLabel = eElement.getElementsByTagName("leftLabel").item(0).getTextContent(); String rightLabel = eElement.getElementsByTagName("rightLabel").item(0).getTextContent(); NodeList leftCardinalityList = eElement.getElementsByTagName("leftCardinality"); NodeList rightCardinalityList = eElement.getElementsByTagName("rightCardinality"); String leftCardinalityMin = ""; String leftCardinalityMax = ""; String rightCardinalityMin = ""; String rightCardinalityMax = ""; for (int j = 0; j < leftCardinalityList.getLength(); j++) { Node node = leftCardinalityList.item(j); leftCardinalityMin = getString(leftCardinalityMin,(Element) node, "min"); leftCardinalityMax = getString(leftCardinalityMax,(Element) node, "max"); } for (int j = 0; j < rightCardinalityList.getLength(); j++) { Node node = rightCardinalityList.item(j); rightCardinalityMin = getString(rightCardinalityMin,(Element) node, "min"); rightCardinalityMax = getString(rightCardinalityMax,(Element) node, "max"); } RelationshipType relationshipType = populateRelationshipType(context,leftType,rightType,leftLabel, rightLabel,leftCardinalityMin, leftCardinalityMax, rightCardinalityMin, rightCardinalityMax); relationshipTypes.add(relationshipType); } } return relationshipTypes; } catch (ParserConfigurationException | SAXException | IOException | SQLException e) { log.error(e, e); } return null; }

Target:
private void parseXMLToRelations(Context context, String fileLocation) throws AuthorizeException { try { File fXmlFile = new File(fileLocation); DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance(); DocumentBuilder dBuilder = null; dBuilder = dbFactory.newDocumentBuilder(); Document doc = dBuilder.parse(fXmlFile); doc.getDocumentElement().normalize(); NodeList nList = doc.getElementsByTagName("type"); List<RelationshipType> relationshipTypes = new LinkedList<>(); for (int i = 0; i < nList.getLength(); i++) { Node nNode = nList.item(i); if (nNode.getNodeType() == Node.ELEMENT_NODE) { Element eElement = (Element) nNode; String leftType = eElement.getElementsByTagName("leftType").item(0).getTextContent(); String rightType = eElement.getElementsByTagName("rightType").item(0).getTextContent(); String leftLabel = eElement.getElementsByTagName("leftLabel").item(0).getTextContent(); String rightLabel = eElement.getElementsByTagName("rightLabel").item(0).getTextContent(); NodeList leftCardinalityList = eElement.getElementsByTagName("leftCardinality"); NodeList rightCardinalityList = eElement.getElementsByTagName("rightCardinality"); String leftCardinalityMin = ""; String leftCardinalityMax = ""; String rightCardinalityMin = ""; String rightCardinalityMax = ""; for (int j = 0; j < leftCardinalityList.getLength(); j++) { Node node = leftCardinalityList.item(j); leftCardinalityMin = getString(leftCardinalityMin,(Element) node, "min"); leftCardinalityMax = getString(leftCardinalityMax,(Element) node, "max"); } for (int j = 0; j < rightCardinalityList.getLength(); j++) { Node node = rightCardinalityList.item(j); rightCardinalityMin = getString(rightCardinalityMin,(Element) node, "min"); rightCardinalityMax = getString(rightCardinalityMax,(Element) node, "max"); } populateRelationshipType(context, leftType, rightType, leftLabel, rightLabel, leftCardinalityMin, leftCardinalityMax, rightCardinalityMin, rightCardinalityMax); } } } catch (ParserConfigurationException | SAXException | IOException | SQLException e) { log.error("An error occurred while parsing the XML file to relations", e); } }