Code example for Document

Methods: getDocumentElement, getElementsByTagName

0
 
	private NodeList getStrings(File file) throws SAXException, IOException, ParserConfigurationException {
		DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();
		DocumentBuilder documentBuilder = documentBuilderFactory.newDocumentBuilder();
		Document document = documentBuilder.parse(file);
		document.getDocumentElement().normalize();
 
		return document.getElementsByTagName("string");
	} 
 
	private List<String> getAllStringNames() throws SAXException, IOException, ParserConfigurationException {
		List<String> allStringNames = new ArrayList<String>();
		List<File> stringFiles = getStringFiles();
 
		for (int i = 0; i < LANGUAGES.length; i++) {
			File stringFile = stringFiles.get(i);
 
			NodeList strings = getStrings(stringFile);
			for (int nodeIndex = 0; nodeIndex < strings.getLength(); nodeIndex++) {
				Node node = strings.item(nodeIndex);
				assertTrue("Node is not an element: " + node.toString(), node.getNodeType() == Node.ELEMENT_NODE);