Browse Source

comit

master
yaroslav 2 years ago
commit
e80b5cef5a
10 changed files with 129 additions and 0 deletions
  1. +10
    -0
      lecturaXML/.classpath
  2. +17
    -0
      lecturaXML/.project
  3. +2
    -0
      lecturaXML/.settings/org.eclipse.core.resources.prefs
  4. +14
    -0
      lecturaXML/.settings/org.eclipse.jdt.core.prefs
  5. +18
    -0
      lecturaXML/bin/lecturaXML/Empleados.xml
  6. BIN
      lecturaXML/bin/lecturaXML/Main.class
  7. BIN
      lecturaXML/bin/module-info.class
  8. +18
    -0
      lecturaXML/src/lecturaXML/Empleados.xml
  9. +40
    -0
      lecturaXML/src/lecturaXML/Main.java
  10. +10
    -0
      lecturaXML/src/module-info.java

+ 10
- 0
lecturaXML/.classpath View File

@ -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-17">
<attributes>
<attribute name="module" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="src" path="src"/>
<classpathentry kind="output" path="bin"/>
</classpath>

+ 17
- 0
lecturaXML/.project View File

@ -0,0 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>lecturaXML</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>

+ 2
- 0
lecturaXML/.settings/org.eclipse.core.resources.prefs View File

@ -0,0 +1,2 @@
eclipse.preferences.version=1
encoding/<project>=UTF-8

+ 14
- 0
lecturaXML/.settings/org.eclipse.jdt.core.prefs View File

@ -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

+ 18
- 0
lecturaXML/bin/lecturaXML/Empleados.xml View File

@ -0,0 +1,18 @@
<?xml version="1.0" encoding="UTF-8"?>
<Empleados>
<empleado id="1">
<apellido>Martinez</apellido>
<dep>10</dep>
<salario>1000.33</salario>
</empleado>
<empleado id="2">
<apellido>Garcia</apellido>
<dep>11</dep>
<salario>2000.34</salario>
</empleado>
<empleado id="3">
<apellido>Navarro</apellido>
<dep>10</dep>
<salario>2222.33</salario>
</empleado>
</Empleados>

BIN
lecturaXML/bin/lecturaXML/Main.class View File


BIN
lecturaXML/bin/module-info.class View File


+ 18
- 0
lecturaXML/src/lecturaXML/Empleados.xml View File

@ -0,0 +1,18 @@
<?xml version="1.0" encoding="UTF-8"?>
<Empleados>
<empleado id="1">
<apellido>Martinez</apellido>
<dep>10</dep>
<salario>1000.33</salario>
</empleado>
<empleado id="2">
<apellido>Garcia</apellido>
<dep>11</dep>
<salario>2000.34</salario>
</empleado>
<empleado id="3">
<apellido>Navarro</apellido>
<dep>10</dep>
<salario>2222.33</salario>
</empleado>
</Empleados>

+ 40
- 0
lecturaXML/src/lecturaXML/Main.java View File

@ -0,0 +1,40 @@
package lecturaXML;
import java.io.File;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
public class Main {
public static void main(String[] args) {
try {
File fil = new File("src/lecturaXML/Empleados.xml");
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
DocumentBuilder builder = factory.newDocumentBuilder();
Document document = builder.parse(new File("src/lecturaXML/Empleados.xml"));
NodeList empleados = document.getElementsByTagName("empleado");
for (int i = 0; i < empleados.getLength(); i++) {
Node node = empleados.item(i);
if (node.getNodeType() == Node.ELEMENT_NODE) {
Element eElement = (Element) node;
if(eElement.hasChildNodes()) {
NodeList nl = node.getChildNodes();
for(int j=0; j<nl.getLength(); j++) {
Node nd = nl.item(j);
System.out.println(nd.getTextContent());
}
}
}
}
System.out.println("Número de empleados: " + empleados.getLength());
} catch(Exception e) {
e.printStackTrace();
}
}
}

+ 10
- 0
lecturaXML/src/module-info.java View File

@ -0,0 +1,10 @@
/**
*
*/
/**
* @author yaros
*
*/
module lecturaXML {
requires java.xml;
}

Loading…
Cancel
Save