Skip to content

Instantly share code, notes, and snippets.

@LuisFcoOrtiz
Last active November 16, 2017 19:19
Show Gist options
  • Save LuisFcoOrtiz/8adde371f2ce3274dc2c0b0131252750 to your computer and use it in GitHub Desktop.
Save LuisFcoOrtiz/8adde371f2ce3274dc2c0b0131252750 to your computer and use it in GitHub Desktop.
Method to read XML file recursively |Método recursivo lectura de fichero XML
/*METODO RECURSIVO PARA LEER XML*/
/*Method to read XML file recursively*/
private void startReader(Node nodeEntry) {
NodeList nodeList = nodeEntry.getChildNodes();
for (int i=0; i<nodeList.getLength(); i++) {
//get the item
Node node = nodeList.item(i);
if (node.getNodeType()== Node.ELEMENT_NODE) {
Element eElement = (Element) node;
//element root (first)
xmlTextArea.append("<" + node.getNodeName());
if (eElement.getAttributes().getLength()>0) {
for (int a=0; a<eElement.getAttributes().getLength(); a++) {
//atributes
//xmlTextArea.append("\t" + eElement.getAttributes().item(a).toString() + "\n");
if (a==eElement.getAttributes().getLength()-1) {
xmlTextArea.append("\t" + eElement.getAttributes().item(a).toString() + "/>");
}
}//loop in whole attributes
}//get all the attributes
}//check elements
if (node.getNodeType()== Node.TEXT_NODE) {
xmlTextArea.append("\t" + node.getTextContent() + "\n");
}//check text
startReader(node);
//close node
if ((node.getNodeType()== Node.ELEMENT_NODE)) {
xmlTextArea.append("<" + node.getNodeName() + "/>");
}
}//loop
}//end startREader
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment