commit 9c02e5db6c1f5c239aed9cfaa65379217f510739 Author: marcos.alcalde1 Date: Fri Oct 23 11:17:31 2026 +0200 Actividad 1.11 - DOM XML, config.properties, Teoria, Practica y gitignore diff --git a/.classpath b/.classpath new file mode 100644 index 0000000..463d5f9 --- /dev/null +++ b/.classpath @@ -0,0 +1,10 @@ + + + + + + + + + + diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..6d62b23 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +/bin/ +.settings/ \ No newline at end of file diff --git a/.project b/.project new file mode 100644 index 0000000..4a5bfd1 --- /dev/null +++ b/.project @@ -0,0 +1,17 @@ + + + Ficheros_11 + + + + + + org.eclipse.jdt.core.javabuilder + + + + + + org.eclipse.jdt.core.javanature + + diff --git a/Actividad 1.11 Tratamiento de ficheros XML con DOM I Marcos Alcalde.pdf b/Actividad 1.11 Tratamiento de ficheros XML con DOM I Marcos Alcalde.pdf new file mode 100644 index 0000000..9084e7c Binary files /dev/null and b/Actividad 1.11 Tratamiento de ficheros XML con DOM I Marcos Alcalde.pdf differ diff --git a/config.properties b/config.properties new file mode 100644 index 0000000..c834fcb --- /dev/null +++ b/config.properties @@ -0,0 +1 @@ +fichero.xml=C:/Users/alcal/aadd/fic11/informacion-IES.xml \ No newline at end of file diff --git a/src/config.properties b/src/config.properties new file mode 100644 index 0000000..95ad6e5 --- /dev/null +++ b/src/config.properties @@ -0,0 +1 @@ +fichero.xml=C:/Users/aadd/fic11/informacion-IES.xml \ No newline at end of file diff --git a/src/module-info.java b/src/module-info.java new file mode 100644 index 0000000..a5a6b9f --- /dev/null +++ b/src/module-info.java @@ -0,0 +1,9 @@ +/** + * + */ +/** + * + */ +module Ficheros_11 { + requires java.xml; +} \ No newline at end of file diff --git a/src/org/palomafp/aadd/mag/GestionInstituto.java b/src/org/palomafp/aadd/mag/GestionInstituto.java new file mode 100644 index 0000000..ea9dcd7 --- /dev/null +++ b/src/org/palomafp/aadd/mag/GestionInstituto.java @@ -0,0 +1,118 @@ +package org.palomafp.aadd.mag; + +import java.io.File; +import java.util.Scanner; + +import javax.xml.parsers.DocumentBuilder; +import javax.xml.parsers.DocumentBuilderFactory; + +import org.w3c.dom.Document; +import org.w3c.dom.Element; +import org.w3c.dom.NodeList; + +public class GestionInstituto { + + private static final String RUTA_XML = "C:/Users/aadd/fic11/informacion-IES.xml"; + + public static void main(String[] args) { + Scanner scanner = new Scanner(System.in); + int opcion = 0; + + try { + File archivo = new File(RUTA_XML); + DocumentBuilderFactory fabrica = DocumentBuilderFactory.newInstance(); + DocumentBuilder constructor = fabrica.newDocumentBuilder(); + Document documento = constructor.parse(archivo); + documento.getDocumentElement().normalize(); + + do { + System.out.println("\n========================================"); + System.out.println(" MENÚ GESTIÓN INSTITUTO (DOM) - FIC11 "); + System.out.println("========================================"); + System.out.println("1. Imprimir instituto"); + System.out.println("2. Imprimir ciclos"); + System.out.println("3. Imprimir módulos filtro 1 (Empiezan por 'Programa')"); + System.out.println("4. Imprimir módulos filtro 2 (Empiezan por 'Programa' del curso 1)"); + System.out.println("5. Salir"); + System.out.print("Selecciona una opción (1-5): "); + + opcion = scanner.nextInt(); + scanner.nextLine(); + + switch (opcion) { + case 1: + imprimirInstituto(documento); + break; + case 2: + imprimirCiclos(documento); + break; + case 3: + imprimirModulosFiltro1(documento); + break; + case 4: + imprimirModulosFiltro2(documento); + break; + case 5: + System.out.println("Saliendo de la aplicación..."); + break; + default: + System.out.println("Opción no válida, no funciona."); + } + } while (opcion != 5); + + } catch (Exception e) { + System.err.println("Error al procesar o cargar el archivo XML: " + e.getMessage()); + e.printStackTrace(); + } finally { + scanner.close(); + } + } + + private static void imprimirInstituto(Document doc) { + Element raiz = doc.getDocumentElement(); + System.out.println("\n--- Datos del instituto ---"); + System.out.println("Nombre: " + raiz.getAttribute("nombre")); + System.out.println("Tipo: " + raiz.getAttribute("tipo")); + } + + private static void imprimirCiclos(Document doc) { + NodeList lista = doc.getElementsByTagName("ciclo"); + System.out.println("\n--- Listado de ciclos ---"); + for (int i = 0; i < lista.getLength(); i++) { + Element c = (Element) lista.item(i); + String codigo = c.getAttribute("codigo"); + String corto = c.getElementsByTagName("nombre_corto").item(0).getTextContent(); + System.out.println("Código: " + codigo + " | Nombre Corto: " + corto); + } + } + + private static void imprimirModulosFiltro1(Document doc) { + NodeList lista = doc.getElementsByTagName("modulo"); + System.out.println("\n--- Módulos que empiezan por 'Programa' ---"); + for (int i = 0; i < lista.getLength(); i++) { + Element m = (Element) lista.item(i); + String titulo = m.getElementsByTagName("titulo").item(0).getTextContent().trim(); + if (titulo.startsWith("Programa")) { + System.out.println("ID: " + m.getAttribute("id") + " | Ref: " + m.getAttribute("ref") + " | Título: " + titulo + " | Horas: " + m.getElementsByTagName("numerohoras").item(0).getTextContent()); + } + } + } + + private static void imprimirModulosFiltro2(Document doc) { + NodeList cursos = doc.getElementsByTagName("curso"); + System.out.println("\n--- Módulos del curso 1 que empiezann por 'Programa' ---"); + for (int i = 0; i < cursos.getLength(); i++) { + Element curso = (Element) cursos.item(i); + if ("1".equals(curso.getAttribute("numero"))) { + NodeList modulos = curso.getElementsByTagName("modulo"); + for (int j = 0; j < modulos.getLength(); j++) { + Element m = (Element) modulos.item(j); + String titulo = m.getElementsByTagName("titulo").item(0).getTextContent().trim(); + if (titulo.startsWith("Programa")) { + System.out.println("[Curso 1] ID: " + m.getAttribute("id") + " | Ref: " + m.getAttribute("ref") + " | Título: " + titulo + " | Horas: " + m.getElementsByTagName("numerohoras").item(0).getTextContent()); + } + } + } + } + } +} \ No newline at end of file