commit 86744f563943e37d91cbcb960ea59afeb2a0f35a Author: AntonioFrische Date: Tue Nov 8 16:09:01 2022 +0100 acabadoAct11 diff --git a/XMLParser/.idea/compiler.xml b/XMLParser/.idea/compiler.xml new file mode 100644 index 0000000..fb7f4a8 --- /dev/null +++ b/XMLParser/.idea/compiler.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/XMLParser/.idea/gradle.xml b/XMLParser/.idea/gradle.xml new file mode 100644 index 0000000..611e7c8 --- /dev/null +++ b/XMLParser/.idea/gradle.xml @@ -0,0 +1,17 @@ + + + + + + + \ No newline at end of file diff --git a/XMLParser/.idea/jarRepositories.xml b/XMLParser/.idea/jarRepositories.xml new file mode 100644 index 0000000..fdc392f --- /dev/null +++ b/XMLParser/.idea/jarRepositories.xml @@ -0,0 +1,20 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/XMLParser/.idea/misc.xml b/XMLParser/.idea/misc.xml new file mode 100644 index 0000000..b9d0bed --- /dev/null +++ b/XMLParser/.idea/misc.xml @@ -0,0 +1,10 @@ + + + + + + + + + + \ No newline at end of file diff --git a/XMLParser/.idea/uiDesigner.xml b/XMLParser/.idea/uiDesigner.xml new file mode 100644 index 0000000..2b63946 --- /dev/null +++ b/XMLParser/.idea/uiDesigner.xml @@ -0,0 +1,124 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/XMLParser/.idea/vcs.xml b/XMLParser/.idea/vcs.xml new file mode 100644 index 0000000..6c0b863 --- /dev/null +++ b/XMLParser/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/XMLParser/gradle/wrapper/gradle-wrapper.jar b/XMLParser/gradle/wrapper/gradle-wrapper.jar new file mode 100644 index 0000000..41d9927 Binary files /dev/null and b/XMLParser/gradle/wrapper/gradle-wrapper.jar differ diff --git a/XMLParser/gradle/wrapper/gradle-wrapper.properties b/XMLParser/gradle/wrapper/gradle-wrapper.properties new file mode 100644 index 0000000..41dfb87 --- /dev/null +++ b/XMLParser/gradle/wrapper/gradle-wrapper.properties @@ -0,0 +1,5 @@ +distributionBase=GRADLE_USER_HOME +distributionPath=wrapper/dists +distributionUrl=https\://services.gradle.org/distributions/gradle-7.4-bin.zip +zipStoreBase=GRADLE_USER_HOME +zipStorePath=wrapper/dists diff --git a/XMLParser/gradlew.bat b/XMLParser/gradlew.bat new file mode 100644 index 0000000..107acd3 --- /dev/null +++ b/XMLParser/gradlew.bat @@ -0,0 +1,89 @@ +@rem +@rem Copyright 2015 the original author or authors. +@rem +@rem Licensed under the Apache License, Version 2.0 (the "License"); +@rem you may not use this file except in compliance with the License. +@rem You may obtain a copy of the License at +@rem +@rem https://www.apache.org/licenses/LICENSE-2.0 +@rem +@rem Unless required by applicable law or agreed to in writing, software +@rem distributed under the License is distributed on an "AS IS" BASIS, +@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +@rem See the License for the specific language governing permissions and +@rem limitations under the License. +@rem + +@if "%DEBUG%" == "" @echo off +@rem ########################################################################## +@rem +@rem Gradle startup script for Windows +@rem +@rem ########################################################################## + +@rem Set local scope for the variables with windows NT shell +if "%OS%"=="Windows_NT" setlocal + +set DIRNAME=%~dp0 +if "%DIRNAME%" == "" set DIRNAME=. +set APP_BASE_NAME=%~n0 +set APP_HOME=%DIRNAME% + +@rem Resolve any "." and ".." in APP_HOME to make it shorter. +for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi + +@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" + +@rem Find java.exe +if defined JAVA_HOME goto findJavaFromJavaHome + +set JAVA_EXE=java.exe +%JAVA_EXE% -version >NUL 2>&1 +if "%ERRORLEVEL%" == "0" goto execute + +echo. +echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. +echo. +echo Please set the JAVA_HOME variable in your environment to match the +echo location of your Java installation. + +goto fail + +:findJavaFromJavaHome +set JAVA_HOME=%JAVA_HOME:"=% +set JAVA_EXE=%JAVA_HOME%/bin/java.exe + +if exist "%JAVA_EXE%" goto execute + +echo. +echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% +echo. +echo Please set the JAVA_HOME variable in your environment to match the +echo location of your Java installation. + +goto fail + +:execute +@rem Setup the command line + +set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar + + +@rem Execute Gradle +"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %* + +:end +@rem End local scope for the variables with windows NT shell +if "%ERRORLEVEL%"=="0" goto mainEnd + +:fail +rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of +rem the _cmd.exe /c_ return code! +if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 +exit /b 1 + +:mainEnd +if "%OS%"=="Windows_NT" endlocal + +:omega diff --git a/XMLParser/settings.gradle b/XMLParser/settings.gradle new file mode 100644 index 0000000..215b381 --- /dev/null +++ b/XMLParser/settings.gradle @@ -0,0 +1,2 @@ +rootProject.name = 'XMLParser' + diff --git a/XMLParser/src/main/java/com/antoniofrische/Empleado.java b/XMLParser/src/main/java/com/antoniofrische/Empleado.java new file mode 100644 index 0000000..052591e --- /dev/null +++ b/XMLParser/src/main/java/com/antoniofrische/Empleado.java @@ -0,0 +1,31 @@ +package com.antoniofrische; + +public class Empleado { + private final String id; + private final String apellido; + private final String departemento; + private final String salario; + + public Empleado(String id, String apellido, String departemento, String salario) { + this.id = id; + this.apellido = apellido; + this.departemento = departemento; + this.salario = salario; + } + + public String getId() { + return id; + } + + public String getApellido() { + return apellido; + } + + public String getDepartemento() { + return departemento; + } + + public String getSalario() { + return salario; + } +} diff --git a/XMLParser/src/main/java/com/antoniofrische/MainXMLParser.java b/XMLParser/src/main/java/com/antoniofrische/MainXMLParser.java new file mode 100644 index 0000000..7c44468 --- /dev/null +++ b/XMLParser/src/main/java/com/antoniofrische/MainXMLParser.java @@ -0,0 +1,13 @@ +package com.antoniofrische; + +import com.antoniofrische.parser.Parser; + +public class MainXMLParser { + public static void main(String[] args) { + Parser parser = new Parser(); + Empleado[] empleados = parser.getEmpleados(); + for (Empleado e: empleados) { + System.out.printf("ID:%s ;Nombre:%s ;Departamento:%s ;Salario:%s€ \n", e.getId(),e.getApellido(), e.getDepartemento(), e.getSalario()); + } + } +} diff --git a/XMLParser/src/main/java/com/antoniofrische/parser/Parser.java b/XMLParser/src/main/java/com/antoniofrische/parser/Parser.java new file mode 100644 index 0000000..5bd8fdf --- /dev/null +++ b/XMLParser/src/main/java/com/antoniofrische/parser/Parser.java @@ -0,0 +1,47 @@ +package com.antoniofrische.parser; + +import com.antoniofrische.Empleado; +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.File; + +public class Parser { + Empleado[] empleados; + + public Parser(){ + File file = new File("C:\\Users\\AntonioFrische\\OneDrive - ABACCO Solutions\\Documents\\Schule_22_23_CFGS\\Acceso_Datos\\IntelliJProyect\\XMLParser\\src\\main\\resources\\Empleados"); + try { + DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance(); + DocumentBuilder dBuilder = dbFactory.newDocumentBuilder(); + Document doc = dBuilder.parse(file); + doc.getDocumentElement().normalize(); + NodeList nList = doc.getElementsByTagName("empleado"); + empleados = new Empleado[nList.getLength()]; + + for (int i = 0; i < nList.getLength(); i++){ + Node nNode = nList.item(i); + if(nNode.getNodeType() == Node.ELEMENT_NODE) { + Element eElement = (Element) nNode; + String id = eElement.getAttribute("id"); + String apellido = eElement.getElementsByTagName("apellido").item(0).getTextContent(); + String departemento = eElement.getElementsByTagName("dep").item(0).getTextContent(); + String salario = eElement.getElementsByTagName("salario").item(0).getTextContent(); + empleados[i] = new Empleado(id,apellido,departemento,salario); + } + } + + } catch(Exception e) { + e.printStackTrace(); + } + } + + public Empleado[] getEmpleados(){ + return empleados; + } +} diff --git a/XMLParser/src/main/resources/Empleados b/XMLParser/src/main/resources/Empleados new file mode 100644 index 0000000..6625b5f --- /dev/null +++ b/XMLParser/src/main/resources/Empleados @@ -0,0 +1,18 @@ + + + + Martinez + 10 + 1000.33 + + + Garcia + 11 + 2000.34 + + + Navarro + 10 + 2222.33 + + \ No newline at end of file