diff --git a/.classpath b/.classpath new file mode 100644 index 0000000..fb50116 --- /dev/null +++ b/.classpath @@ -0,0 +1,6 @@ + + + + + + diff --git a/.project b/.project new file mode 100644 index 0000000..69453f2 --- /dev/null +++ b/.project @@ -0,0 +1,17 @@ + + + Ejercicio_10 + + + + + + org.eclipse.jdt.core.javabuilder + + + + + + org.eclipse.jdt.core.javanature + + diff --git a/DOMEmpleados.xml b/DOMEmpleados.xml new file mode 100644 index 0000000..5cca44f --- /dev/null +++ b/DOMEmpleados.xml @@ -0,0 +1,18 @@ + + + + Martinez + 10 + 1000.33 + + + Garcia + 11 + 2000.34 + + + Navarro + 10 + 2222.33 + + \ No newline at end of file diff --git a/README.md b/README.md index 24a86ec..fa86757 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,35 @@ # Ejercicio_10 +### Introduccion +Ejercicio de lectura de un arachivo ".xml" con DOM + + +### Documentacion + +~~~ +import java.io.File; +import javax.xml.parsers.*; +import org.w3c.dom.*; +~~~ + +### Salida por pantalla +~~~ + +Empleados : 3 +----------------------- + id: 1 +apellido: Martinez +departamento: 10 +salario: 1000.33 +----------------------- + id: 2 +apellido: Garcia +departamento: 11 +salario: 2000.34 +----------------------- + id: 3 +apellido: Navarro +departamento: 10 +salario: 2222.33 + +~~~ \ No newline at end of file diff --git a/bin/com/jorpelu/LecturaXML.class b/bin/com/jorpelu/LecturaXML.class new file mode 100644 index 0000000..3debdf4 Binary files /dev/null and b/bin/com/jorpelu/LecturaXML.class differ diff --git a/bin/module-info.class b/bin/module-info.class new file mode 100644 index 0000000..eb8e2fa Binary files /dev/null and b/bin/module-info.class differ diff --git a/src/com/jorpelu/LecturaXML.java b/src/com/jorpelu/LecturaXML.java new file mode 100644 index 0000000..007b48a --- /dev/null +++ b/src/com/jorpelu/LecturaXML.java @@ -0,0 +1,40 @@ +package com.jorpelu; + +import java.io.File; +import javax.xml.parsers.*; +import org.w3c.dom.*; + +public class LecturaXML { + + public static void main(String[] args) { + File file = new File("DOMEmpleados.xml"); + + try { + DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); + DocumentBuilder db = dbf.newDocumentBuilder(); + Document doc = db.parse(file); + doc.getDocumentElement().normalize(); + NodeList lista = doc.getElementsByTagName("empleado"); + System.out.println("Empleados : " + lista.getLength()); + + for (int i = 0; i