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.

XML Parsing

Empfohlene Antworten

Veröffentlicht

hi,

ich will aus nem xml-file ganz bestimmte teile auslesen und in einer datenbank speichern, kann mir einer nen heißen tipp geben wie ich die ganze sache auslese? das einspielen in die db ist kein problem.

thx im voraus...

met

danke dir, hab gerade auch noch eine gut sache entdeckt:

"j4dom",

met

j4dom kenne ich nicht, ich kenne nur dom4j ;)

jepp, das mein ich...

habs so gemacht, falls es einer wissen will:

SAXReader sxread = new SAXReader();

InputStream iss = null;

try {

iss = new FileInputStream(new File("c:/xml_test2.xml"));

InputSource is = new InputSource(iss);

sxread.setMergeAdjacentText(false);

doc = sxread.read(is);

Element root = doc.getRootElement();

Element xpert = root.element("Xpert");

Element textbox = xpert.element("X_Textbox");

Element etext = textbox.element("E_Text");

System.out.println(etext.getText()); // nur ne Ausgabe um zu testen ob es funzt...

} catch (DocumentException e) {

// TODO Auto-generated catch block

e.printStackTrace();

} catch (FileNotFoundException e1) {

// TODO Auto-generated catch block

e1.printStackTrace();

}

}

Hi, ich bin hier grad so reingeschneit ;)

Zu Java und XML kann ich nur die Libs von JDOM

empfehlen.

http://jdom.org/

Ein kleiner Beispielcode könnte so aussehen:

import java.util.List;

import java.io.FileReader;

import org.jdom.input.SAXBuilder;

import org.jdom.Document;

import org.jdom.Element;

import org.jdom.JDOMException;

public class ReadXML

{

public static void main(String[] args)

{

try

{

SAXBuilder sax = new SAXBuilder();

Document d = sax.build(new FileReader("deineXML.xml"));

Element root = d.getRootElement();

List rootChildren = root.getChildren();

}

catch(IOException ioex)

{

ioex.printStackTrace();

}

catch(JDOMException jdomex)

{

jdomex.printStackTrace();

}

}

}

Danach könnte man die Liste entweder mit Enumeration oder mit nem Iterator durchlaufen

neue Elemente erstellen(Tipp: CASTEN) und so weiter und so weiter...

Hallo :D

wir arbeiten auch mit xml-files über die wir verschiedene maschinendaten einlesen.

das ganze geschrieht über ein DOM-tree, also so wie schon beschrieben wurde. die einzelnen zweige arbeitest du dann ab, da könnte so aussehen

private objectX objectX(Node node) {

objectX table = new objectX();

NodeUtil.fillAllPrimitives(table, node);

Object ref = table.getReferencedObject(node);

if(ref == null || ! ( ref instanceof objectX) ) {

xmc.warn("Found no reference objectX for mcdTable:",node);

} else {

table.setobjectX((objectX)ref);

table.getobjectX().setobjectX(table);

}

return table;

}

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.