Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Entrega Práctica 3 Parseado XML #16

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added Práctica/MemoriadelaSolucion.docx
Binary file not shown.
10 changes: 10 additions & 0 deletions Práctica/PracticaResuelta/.classpath
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-14">
<attributes>
<attribute name="module" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="src" path="src"/>
<classpathentry kind="output" path="bin"/>
</classpath>
17 changes: 17 additions & 0 deletions Práctica/PracticaResuelta/.project
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>PrcaticaExtraerDatos</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
</projectDescription>
14 changes: 14 additions & 0 deletions Práctica/PracticaResuelta/.settings/org.eclipse.jdt.core.prefs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
org.eclipse.jdt.core.compiler.codegen.targetPlatform=14
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
org.eclipse.jdt.core.compiler.compliance=14
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=14
Binary file added Práctica/PracticaResuelta/CapturaResultado.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
76 changes: 76 additions & 0 deletions Práctica/PracticaResuelta/src/Practica3/Prcatica3.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
package Practica3;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.List;

import javax.xml.stream.XMLInputFactory;
import javax.xml.stream.XMLStreamException;
import javax.xml.stream.XMLStreamReader;

public class Prcatica3 {
//buscamos el xml
public static final String DOCUMENTO_XML = "C:\\Users\\mrmar\\OneDrive\\Escritorio\\Universidad\\1�Cuatri\\Desarrollo E Integraci�n De Software\\EjemploStAX-main\\Pr�ctica\\empleados.xml";
public static final String SALARIO = "salario";
public static final String NOMBRE = "nombre";


public static List<String> numeroDePlazas() throws FileNotFoundException, IOException {
System.out.println("Iniciando el documento");
List<String> resul = new ArrayList<String>();
String nombreTemp = null;
XMLInputFactory xmlInputFactory = XMLInputFactory.newFactory();
InputStream inputStream = null;
XMLStreamReader xmlStreamReader = null;

try {
inputStream = new FileInputStream(DOCUMENTO_XML);
xmlStreamReader = xmlInputFactory.createXMLStreamReader(inputStream);
//recorremos el xml
while (xmlStreamReader.hasNext()) {
xmlStreamReader.next();

if(xmlStreamReader.isStartElement() && NOMBRE.equals(xmlStreamReader.getLocalName())) {
//guardamos el nombre y despues comprobaremos si su salario es mayor de 30000
nombreTemp=xmlStreamReader.getElementText();

}
if (xmlStreamReader.isStartElement() && SALARIO.equals(xmlStreamReader.getLocalName())) {
String salarioTemp=xmlStreamReader.getElementText();
//buscamos lo que tiene un salio mayor o igual a 30000
if (Integer.parseInt(salarioTemp)>=30000) {
//lo a�adimos a la lista
resul.add(nombreTemp);
}


}
}
} catch (XMLStreamException ex) {
ex.printStackTrace();
} finally {try {
if (xmlStreamReader != null) xmlStreamReader.close();
if (inputStream != null) inputStream.close();
} catch (XMLStreamException ex) {
ex.printStackTrace();
}
}
System.out.println("Fin del documento");
return resul;
}
public static void main(String[] args) {
try {
//imprimimos el resultado
System.out.println("Empleados con salario mayor a 30000: "+ numeroDePlazas());
} catch (IOException e) {
e.printStackTrace();
}


}


}
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,6 @@ StAX (Streaming API for XML) es el API más reciente de JAXP (Java API for XML P
Puedes consultar la documentación oficial en este enlace: https://docs.oracle.com/javase/tutorial/jaxp/stax/index.html
<br>
En esta página puedes ver un buen ejemplo de cómo generar documentos XML válidos: https://www.tutorialspoint.com/java_xml/java_stax_modify_document.htm


Cambio realizado por Marcos Rodriguezd
Empty file added adsesf.txt
Empty file.