From 5704d4d1dcc8f3eb51c2d46a1923ec49ce80805c Mon Sep 17 00:00:00 2001 From: Daniel Date: Sun, 27 Nov 2022 20:01:36 +0100 Subject: [PATCH] first commit --- Actividad10/.classpath | 10 ++++ Actividad10/.project | 17 +++++++ .../org.eclipse.core.resources.prefs | 2 + .../.settings/org.eclipse.jdt.core.prefs | 14 ++++++ Actividad10/README.md | 27 ++++++++++ Actividad10/bin/EmpleadoParser.class | Bin 0 -> 2558 bytes Actividad10/bin/Main.class | Bin 0 -> 766 bytes Actividad10/empleados.xml | 22 +++++++++ Actividad10/src/EmpleadoParser.java | 46 ++++++++++++++++++ Actividad10/src/Main.java | 14 ++++++ 10 files changed, 152 insertions(+) create mode 100644 Actividad10/.classpath create mode 100644 Actividad10/.project create mode 100644 Actividad10/.settings/org.eclipse.core.resources.prefs create mode 100644 Actividad10/.settings/org.eclipse.jdt.core.prefs create mode 100644 Actividad10/README.md create mode 100644 Actividad10/bin/EmpleadoParser.class create mode 100644 Actividad10/bin/Main.class create mode 100644 Actividad10/empleados.xml create mode 100644 Actividad10/src/EmpleadoParser.java create mode 100644 Actividad10/src/Main.java diff --git a/Actividad10/.classpath b/Actividad10/.classpath new file mode 100644 index 0000000..57bca72 --- /dev/null +++ b/Actividad10/.classpath @@ -0,0 +1,10 @@ + + + + + + + + + + diff --git a/Actividad10/.project b/Actividad10/.project new file mode 100644 index 0000000..e761406 --- /dev/null +++ b/Actividad10/.project @@ -0,0 +1,17 @@ + + + Actividad10 + + + + + + org.eclipse.jdt.core.javabuilder + + + + + + org.eclipse.jdt.core.javanature + + diff --git a/Actividad10/.settings/org.eclipse.core.resources.prefs b/Actividad10/.settings/org.eclipse.core.resources.prefs new file mode 100644 index 0000000..99f26c0 --- /dev/null +++ b/Actividad10/.settings/org.eclipse.core.resources.prefs @@ -0,0 +1,2 @@ +eclipse.preferences.version=1 +encoding/=UTF-8 diff --git a/Actividad10/.settings/org.eclipse.jdt.core.prefs b/Actividad10/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..8c9943d --- /dev/null +++ b/Actividad10/.settings/org.eclipse.jdt.core.prefs @@ -0,0 +1,14 @@ +eclipse.preferences.version=1 +org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled +org.eclipse.jdt.core.compiler.codegen.targetPlatform=17 +org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve +org.eclipse.jdt.core.compiler.compliance=17 +org.eclipse.jdt.core.compiler.debug.lineNumber=generate +org.eclipse.jdt.core.compiler.debug.localVariable=generate +org.eclipse.jdt.core.compiler.debug.sourceFile=generate +org.eclipse.jdt.core.compiler.problem.assertIdentifier=error +org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures=disabled +org.eclipse.jdt.core.compiler.problem.enumIdentifier=error +org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures=warning +org.eclipse.jdt.core.compiler.release=enabled +org.eclipse.jdt.core.compiler.source=17 diff --git a/Actividad10/README.md b/Actividad10/README.md new file mode 100644 index 0000000..6488974 --- /dev/null +++ b/Actividad10/README.md @@ -0,0 +1,27 @@ +## Título +Actividad 10 - Leer archivo .xml por pantalla + +## Uso +Creamos una clase que sea capaz de interpretar los datos de un archivo xml y mostrarlos por pantalla +``` +idEmpleado: 1 +Apellido: Lautaro +Departamento: 12 +Salario: 1500.99 + +idEmpleado: 2 +Apellido: Rodriguez +Departamento: 1 +Salario: 2900 + +idEmpleado: 3 +Apellido: Martinez +Departamento: 33 +Salario: 2400.50 + +idEmpleado: 4 +Apellido: Conejero +Departamento: 22 +Salario: 6045 + +``` \ No newline at end of file diff --git a/Actividad10/bin/EmpleadoParser.class b/Actividad10/bin/EmpleadoParser.class new file mode 100644 index 0000000000000000000000000000000000000000..b45b3394590ea4651612f315215ed0ce903cff5e GIT binary patch literal 2558 zcma)7OLJ3Y7=FGa%}LVJ3%y}LAqa)06rv(k(}GecP)#qA8Yp->O%CaSW4bO8@a?xU zdI(;$t5DD(;2nsj6s!?gTho^w8{&r0iEgPJ2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+%2&Y{o~}f)(`RN9z27ZS)z%?-;}%7;_u@dIAQE1cy9e2-Ugj_`=$TfBzXsXv6Pcmr>8ZgE_|TX>s*Nm2F=^@5D)!@GEo z{?0SrZnRuu$^ivJDA=eVs$i#rVFjZC_*>qL{e|<_2pEsl0ksw-?%t=d2Os20)TDJb@*EU!%XGFOP^w=??I4GWLEIL|FA+;V7B6t7W( zLR^fv5Q1xR|Cfe(3N~6=%*$!6a5I+eL~`)yK#rHYa5}*>94I59fNd7iGEHF%9G3qA zNbtt(^0er+X$5U+cZT$N9Cmn`Fp$Izo|y%JHcQXO8rJz@lE0EDL0g+6*PElzE8Lu+ zJj15j{Ej>Czai_+QSCKnc<}2yW+`J6J8Z<%C^H-6$s^6XjS644S;N$<#?9972z7dS cA{*ExLxs2|9`p7j&Q0_z?AUZ$bQ5U*1$X+O6aWAK literal 0 HcmV?d00001 diff --git a/Actividad10/empleados.xml b/Actividad10/empleados.xml new file mode 100644 index 0000000..01cd037 --- /dev/null +++ b/Actividad10/empleados.xml @@ -0,0 +1,22 @@ + + + Lautaro + 12 + 1500.99 + + + Rodriguez + 1 + 2900 + + + Martinez + 33 + 2400.50 + + + Conejero + 22 + 6045 + + \ No newline at end of file diff --git a/Actividad10/src/EmpleadoParser.java b/Actividad10/src/EmpleadoParser.java new file mode 100644 index 0000000..fea7134 --- /dev/null +++ b/Actividad10/src/EmpleadoParser.java @@ -0,0 +1,46 @@ +import org.w3c.dom.Document; +import org.w3c.dom.Element; +import org.w3c.dom.Node; +import org.w3c.dom.NodeList; + +import javax.xml.parsers.DocumentBuilder; +import javax.xml.parsers.DocumentBuilderFactory; +import java.io.*; + +public class EmpleadoParser { + + private final InputStream empleadosFile; + + public EmpleadoParser(File location) throws IOException { + empleadosFile = new FileInputStream(location); + } + + public boolean parse() { + boolean parsed = false; + + try { + DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); + DocumentBuilder builder = factory.newDocumentBuilder(); + Document dom = builder.parse(empleadosFile); + Element root = dom.getDocumentElement(); + NodeList items = root.getElementsByTagName("empleado"); + + for(int i = 0; i < items.getLength(); i++) { + Node node = items.item(i); + if(node.getNodeType() != Node.ELEMENT_NODE) { + throw new RuntimeException("Error in XML document, check xml syntax"); + } + Element element = (Element) node; + System.out.printf("idEmpleado: %s \n",element.getAttribute("id")); + System.out.printf("Apellido: %s\n",element.getElementsByTagName("apellido").item(0).getTextContent()); + System.out.printf("Departamento: %s\n",element.getElementsByTagName("dep").item(0).getTextContent()); + System.out.printf("Salario: %s\n\n",element.getElementsByTagName("salario").item(0).getTextContent()); + } + parsed = true; + + } catch (Exception e) { + e.printStackTrace(); + } + return parsed; + } +} diff --git a/Actividad10/src/Main.java b/Actividad10/src/Main.java new file mode 100644 index 0000000..77a764c --- /dev/null +++ b/Actividad10/src/Main.java @@ -0,0 +1,14 @@ +import java.io.File; +import java.io.IOException; + +public class Main { + public static void main(String[] args) { + try { + EmpleadoParser empleadoParser = new EmpleadoParser(new File("empleados.xml")); + empleadoParser.parse(); + } catch (IOException e) { + throw new RuntimeException(e); + } + + } +} \ No newline at end of file