valor de la etiquetas xml

public void leerXMLNodesInner(Document original,Node currentNode, String path,List laplanado){
String newPath = path + currentNode.getNodeName();

if (!currentNode.getNodeName().equals("#document")){

     String finalPath = newPath;

try {
Node foundNode = (Node)xpath.evaluate(finalPath+"/text()", original, XPathConstants.NODE);

String paths = finalPath;
if (foundNode!=null){
if (foundNode.getNodeType() == Element.TEXT_NODE){

String value = foundNode.getNodeValue().trim();

}
}else{
System.out.println("path "+paths +" value null");
}

} catch (XPathExpressionException e) {
private static void leerXMLNodes(Document original){ leerXMLNodesInner(original,original.getFirstChild(), "/"); } System.out.println("Error xPath expersion "+e.getMessage());
} catch (DOMException e) {
System.out.println("Error DOME expersion "+e.getMessage());
}

> NodeList listaHijos = currentNode.getChildNodes();
if(listaHijos != null){
for(int i = 0; i < listaHijos.getLength(); i++){
Node currentChild = listaHijos.item(i);
if(currentChild.getNodeType() != Node.TEXT_NODE && currentChild.getNodeType() != Node.COMMENT_NODE){
leerXMLNodesInner(original,currentChild, newPath+"/");
}
}
}
}else{
System.out.println("Fin del fichero");
}

}


para saber el valor que tiene la etiqueta utilizamos

Node foundNode = (Node)xpath.evaluate(finalPath+»/text()», original, XPathConstants.NODE);

preguntamos por el tipo y el nodo

if (foundNode.getNodeType() == Element.TEXT_NODE){


cogemos el valor de la etiqueta

String value = foundNode.getNodeValue().trim();




Deja una respuesta

Tu dirección de correo electrónico no será publicada. Los campos obligatorios están marcados con *