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.

java dom ( XML _Baum)

Empfohlene Antworten

Ich habe Probleme um meine gesamten Baum in Java Dom zu erstellen (public void update() ). Ich habe nur bis zum Knoten <ECUsListe/> (Bzw. <AKTORsListe/>,... ). Ich weiss nicht wie es weiter geht.


package view.hw;


import java.awt.BorderLayout;

import java.awt.Component;

import java.awt.event.ActionEvent;

import java.awt.event.KeyEvent;


import javax.swing.ImageIcon;

import javax.swing.JFrame;

import javax.swing.JMenu;

import javax.swing.JMenuBar;

import javax.swing.JMenuItem;

import javax.swing.JTabbedPane;

import javax.swing.KeyStroke;


import model.ModelFailureStructure;

import model.ModelGeneralTreeSystem;


import org.w3c.dom.Node;

import org.w3c.dom.NodeList;


import run.StartFA;

import view.TreeSystem;

import controller.ListenerOpen;

import controller.ListenerSave;

import controller.hw.ExitListener;

import data.filebase.FailureModelFile;


public class Editor extends JFrame {


	public static Editor editor = null;


	private static final long serialVersionUID = 1L;


	private Ecu ecu;

	private Aktor aktor;

	private Sensor sensor;

	private Bus bus;

	private Gateway gateway;


	public Editor(Component pane, ModelGeneralTreeSystem mgts,

			ModelFailureStructure mfs, TreeSystem tac) {

		editor = this;

		methode(pane, mgts, mfs, tac);

		this.setTitle("FehlermodellierungsEditor");

		this.setSize(800, 400);

		this.setVisible(true);

		update();

	}


	public void methode(Component pane, ModelGeneralTreeSystem mgts,

			ModelFailureStructure mfs, TreeSystem tac) {

		JMenuItem openItem, exitItem;

		final JMenuItem saveItem;

		JMenuBar menuBar = new JMenuBar();

		setJMenuBar(menuBar);

		setDefaultCloseOperation(EXIT_ON_CLOSE);


		JMenu fileMenu = (JMenu) menuBar.add(new JMenu("File"));

		fileMenu.setMnemonic(KeyEvent.VK_F);

		menuBar.add(fileMenu);


		openItem = new JMenuItem(" Open ", new ImageIcon("./img/open.gif"));

		openItem.setMnemonic(KeyEvent.VK_O);

		openItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_O,

				ActionEvent.CTRL_MASK));

		fileMenu.add(openItem);

		fileMenu.addSeparator();

		saveItem = new JMenuItem(" Save ", new ImageIcon("./img/save1.gif"));

		saveItem.setMnemonic(KeyEvent.VK_S);

		saveItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_S,

				ActionEvent.CTRL_MASK));

		fileMenu.add(saveItem);

		fileMenu.addSeparator();

		exitItem = new JMenuItem(" Exit ", new ImageIcon("./img/exit.gif"));

		exitItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_E,

				ActionEvent.CTRL_MASK));

		exitItem.setMnemonic(KeyEvent.VK_E);

		fileMenu.add(exitItem);


		ecu = new Ecu();

		aktor = new Aktor();

		sensor = new Sensor();

		bus = new Bus();

		gateway = new Gateway();


		JTabbedPane tp = new JTabbedPane();

		tp.add("    ECU ", ecu.getHauptPanel());

		tp.add("    AKTOR ", aktor.getHauptPanel());

		tp.add("    SENSOR ", sensor.getHauptPanel());

		tp.add("    BUS ", bus.getHauptPanel());

		tp.add("    GATEWAY ", gateway.getHauptPanel());


		this.getContentPane().setLayout(new BorderLayout());

		this.getContentPane().add(menuBar);

		this.getContentPane().add(tp);

		setJMenuBar(menuBar);


		exitItem.addActionListener(new ExitListener());

		openItem.addActionListener(new ListenerOpen(pane, mgts, mfs));

		saveItem.addActionListener(new ListenerSave(tac, (JFrame) pane));

	}


	public void update() {

		FailureModelFile smm = (FailureModelFile) StartFA.factory

				.getSimulinkModel(null);

		Node root = smm.getRootNode();


		// doc = XML-DOKUMENT

		NodeList childList1 = root.getChildNodes();

		boolean existImplementationNode = false;

		boolean ecuExist = false;

		boolean busExist = false;

		boolean sensorExist = false;

		boolean aktorExist = false;

		boolean gatewayExist = false;

		for(int childcount1 = 0; childcount1 < childList1.getLength(); childcount1++) {

			Node child1 = childList1.item(childcount1);

			if (child1.getNodeName().equals("Implementierung")) {

				existImplementationNode = true;

				NodeList childLst2 = child1.getChildNodes();

				for (int childcount2 = 0; childcount2 < childLst2.getLength(); childcount2++) {

					Node child2 = childLst2.item(childcount2);

					if (child2.getNodeName().equals("ECUsListe")) {

						ecuExist = true;

					}

					if (!ecuExist) {

						Node ecuNode = child1.getOwnerDocument().createElement(

								"ECUsListe");

						child1.appendChild(ecuNode);

						ecuExist = true;

					}

					if (child2.getNodeName().equals("AKTORsListe")) {

						aktorExist = true;

					}

					if (!aktorExist) {

						Node aktorNode = child1.getOwnerDocument()

								.createElement("AKTORsListe");

						child1.appendChild(aktorNode);

						aktorExist = true;

					}

					if (child2.getNodeName().equals("SENSORsListe")) {

						sensorExist = true;

					}

					if (!sensorExist) {

						Node sensorNode = child1.getOwnerDocument()

								.createElement("SENSORsListe");

						child1.appendChild(sensorNode);

						sensorExist = true;

					}

					if (child2.getNodeName().equals("BUSsListe")) {

						busExist = true;

					}

					if (!busExist) {

						Node busNode = child1.getOwnerDocument().createElement(

								"BUSsListe");

						child1.appendChild(busNode);

						busExist = true;

					}

					if (child2.getNodeName().equals("GATEWAYsListe")) {

						gatewayExist = true;


					}

					if (!gatewayExist) {

						Node gatewayNode = child1.getOwnerDocument()

								.createElement("GATEWAYsListe");

						child1.appendChild(gatewayNode);

						gatewayExist = true;

					}


				}

			}

			if (!existImplementationNode) {

				Node implementationNode = root.getOwnerDocument()

						.createElement("Implementierung");

				System.out.println("iii;");

				root.appendChild(implementationNode);


				Node ecuNode = implementationNode.getOwnerDocument().createElement("ECUsListe");

				Node aktorNode = implementationNode.getOwnerDocument().createElement(

						"AKTORsListe");

				Node sensorNode = implementationNode.getOwnerDocument().createElement(

						"SENSORsListe");

				Node busNode = implementationNode.getOwnerDocument()

						.createElement("BUSsListe");

				Node gatewayNode = implementationNode.getOwnerDocument().createElement(

						"GATEWAYsListe");

				implementationNode.appendChild(ecuNode);

				implementationNode.appendChild(aktorNode);

				implementationNode.appendChild(sensorNode);

				implementationNode.appendChild(busNode);

				implementationNode.appendChild(gatewayNode);


				existImplementationNode = true;

				ecuExist = true;

				busExist = true;

				sensorExist = true;

				aktorExist = true;

				gatewayExist = true;

			}

			System.out.println("XXX;");


			}

	}

}


So sieht der XMl-Baum:

<System>

<Implementierung>

<ECUsListe>

<ECU-Name> ecu1 <ECU-Name/>

<FehlerEigenschaften>

<FehlerName = "Falscher Wert">

<FehlerWahrscheinlichkeit> 0.001 </FehlerWahrscheinlichkeit>

</FehlerName>

<FehlerName = "Wert unerwünscht">

<FehlerWahrscheinlichkeit> 0.00018 </FehlerWahrscheinlichkeit>

</FehlerName>

<FehlerName = "Rest">

<FehlerWahrscheinlichkeit> 0.041 </FehlerWahrscheinlichkeit>

</FehlerName>

........

</FehlerEigenschaften>

<ECU-Name> ecu2 <ECU-Name/>

<FehlerEigenschaften>

<FehlerName = "Falscher Wert">

<FehlerWahrscheinlichkeit> 0.001 </FehlerWahrscheinlichkeit>

</FehlerName>

<FehlerName = "Wert unerwünscht">

<FehlerWahrscheinlichkeit> 0.00018 </FehlerWahrscheinlichkeit>

</FehlerName>

<FehlerName = "Rest">

<FehlerWahrscheinlichkeit> 0.041 </FehlerWahrscheinlichkeit>

</FehlerName>

........

</FehlerEigenschaften>

.........

<ECU-Name> .........

</ECUsListe>

+<AKTORsListe/>

+<SENSORsListe/>

+<BUSsListe/>

+<GATEWAYsListe/>

Bsp.:

- <System>

-<Signal>

- .....

- <Implementierung>

- <ECUsListe>

<ECU-Name>ecu1</ECU-Name>

<ECU-Name>ecu64</ECU-Name>

</ECUsListe>

- <AKTORsListe>

<AKTOR-Name>akhfalkhf</AKTOR-Name>

</AKTORsListe>

<SENSORsListe />

<BUSsListe />

<GATEWAYsListe />

</Implementierung>

</System>

Danke vorraus!

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.