Zum Inhalt springen
View in the app

A better way to browse. Learn more.

Fachinformatiker.de

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

JaxP XML null

Empfohlene Antworten

Veröffentlicht

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

Das ist doch auch vollkommen klar wieso dein Element t null ist.

Denn du erzeugst ein neues Element willst aber eigentlich mit dem Docuement arbeiten.


Element root = doc.getRootElement();

// jetzt hast du das root Element und kannst damit weiter arbeiten


Ich danke recht herzlich, oft sieht man den Wald vor lauter Bäumen nicht.

Danke für die Hilfe.

Georg

Archiv

Dieses Thema wurde archiviert und kann nicht mehr beantwortet werden.

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.