Zum Inhalt springen

schliz

Mitglieder
  • Gesamte Inhalte

    2
  • Benutzer seit

  • Letzter Besuch

  1. schliz

    JaxP XML null

    Ich danke recht herzlich, oft sieht man den Wald vor lauter Bäumen nicht. Danke für die Hilfe. Georg
  2. schliz

    JaxP XML null

    Ich habe ein Application.dtd <!ELEMENT Applications (Application*)> <!ELEMENT Application (Name,Pfad,JarFileName,MainClass,Subclasses,Application*)> <!ELEMENT Name (#PCDATA)> <!ELEMENT Pfad (#PCDATA)> <!ELEMENT JarFileName (#PCDATA)> <!ELEMENT MainClass (#PCDATA)> <!ELEMENT Subclasses (Subclass*) > <!ELEMENT Subclass (#PCDATA)> ein Application.xml <?xml version="1.0" encoding='ISO-8859-1'?> <!DOCTYPE Applications SYSTEM "Application.dtd"> <!-- <!DOCTYPE Application SYSTEM "Application.dtd"> --> <!-- Wurzelelement--> <Applications> <Application> <Name>MainApplication</Name> <Pfad>.</Pfad> <JarFileName>test.jar</JarFileName> <MainClass>Main</MainClass> <Subclasses> <Subclass>Howdy</Subclass> <Subclass>TestClass</Subclass> </Subclasses> <Application> <Name>MainApplication</Name> <Pfad>.</Pfad> <JarFileName>test.jar</JarFileName> <MainClass>Main</MainClass> <Subclasses> <Subclass>Howdy</Subclass> <Subclass>TestClass</Subclass> </Subclasses> </Application> </Application> </Applications> mein Code sieht wie folgt aus: import org.jdom.input.SAXBuilder; import org.jdom.Document; import org.jdom.JDOMException; import org.jdom.*; String DateiName = "Application.xml"; Document doc = null; SAXBuilder b = new SAXBuilder(true); // validierenden Parser nutzen try { doc = b.build(new File(DateiName)); } catch (JDOMException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } try { Element root= new Element("Applications"); System.out.println(root.toString()); Element t = root.getChild("Application"); // Name der Application als String speichern String name = t.getChild("Name").getText(); System.out.println(name); Element tnext = root.getChild("Application"); name = t.getChild("Name").getText(); System.out.println(name); } catch (Exception e) { // Ausnahmebehandlung hier nur rudimentär System.out.println(e.toString()); } Mein Problem: root, sieht so aus als ob es leer wäre? Wenn ich Element t = root.getChild("Application"); aufrufe, ist t null. Was mache ich falsch? Ich danke für eure Hilfe. Georg

Fachinformatiker.de, 2024 by SE Internet Services

fidelogo_small.png

Schicke uns eine Nachricht!

Fachinformatiker.de ist die größte IT-Community
rund um Ausbildung, Job, Weiterbildung für IT-Fachkräfte.

Fachinformatiker.de App

Download on the App Store
Get it on Google Play

Kontakt

Hier werben?
Oder sende eine E-Mail an

Social media u. feeds

Jobboard für Fachinformatiker und IT-Fachkräfte

×
×
  • Neu erstellen...