Xpath & JDOM Element Pfad ausgeben

TJava

Bekanntes Mitglied
Hallo ich habe folgende Datei, diese erstellt mir eine Ordnerstruktur. Nun möchte ich gerne das Dokument lesen und die Pfad angaben zu diesen Elementen haben.
Bsp.:
/WorkspaceAutoIt/Hilfsdateien/SF0-Dateien/NA
/WorkspaceAutoIt/Hilfsdateien/SQL_Script

Guten Morgen :)

[XML]<dirs baseDir="/WorkspaceAutoIt">



<dir name="Hilfsdateien">

<dir name="SF0-Dateien" AutoItFileType="SF0_SCRIPT">
<dir name="NA" AutoItFileType="NA_FILE"></dir>
</dir>

<dir name="SQL-Dateien" AutoItFileType="SQL_SCRIPT"></dir>

<dir name="X400"></dir>

<dir name="Diskette"></dir>

<dir name="Andere_Dateien"></dir>

</dir>

<dir name="Hilfstools">
</dir>

<dir name="Logs">
<dir name="ServerDateien"></dir>
<dir name="Vergleichsdokumente"></dir>
</dir>

<dir name="Referenzdocs" AutoItFileType="REF_FILE">
</dir>

<dir name="Skripte">
</dir>

<dir name="Standardskripte">
<dir name="test"></dir>
</dir>

</dirs>[/XML]
 

TJava

Bekanntes Mitglied
Danke und hier ist die Lösung:)
Wo kann ich denn genau den BLog anlegen?



Java:
import java.io.File;
import java.io.IOException;
import java.util.List;

import org.jdom.Document;
import org.jdom.Element;
import org.jdom.JDOMException;
import org.jdom.input.SAXBuilder;

public class GetFolder {

	private String fileTypeName;
	private File folder;

	public GetFolder(String fileTypeName) throws JDOMException, IOException {
		this.fileTypeName = fileTypeName;

		SAXBuilder builder = new SAXBuilder();
		Document doc = builder.build(new File("AutoItWorkspace.xml"));
		Element root = doc.getRootElement();

		File baseDir = new File(root.getAttribute("baseDir").getValue());

		List<Element> dirs = root.getChildren("dir");
		for (Element dir : dirs) {
			_makeDirs(baseDir, dir, fileTypeName);

		}
	}

	private File _makeDirs(File parent, Element dir, String fileTypeName) {
		File file = new File(parent, dir.getAttribute("name").getValue());

		String vergleich = dir.getAttribute("FileType").getValue();

		if (vergleich.contentEquals(fileTypeName)) {
			this.folder = file;
		} else {

		}

		List<Element> children = dir.getChildren("dir");
		if (!children.isEmpty()) {
			for (Element child : children) {
				_makeDirs(file, child, this.fileTypeName);
			}
		}
		return null;
	}

	public File getFolder() {
		return this.folder;
	}

}
 
Ähnliche Java Themen
  Titel Forum Antworten Datum
M JDOM und XPath, zu Element zugehörigen XPath-Ausdruck XML & JSON 5
G JDOM - aus Children-Liste ein Child direkt ansprechen ohne XPath? XML & JSON 9
T EXSD auslesen mit XPath und JDOM XML & JSON 8
C XPath in JDOM klappt nicht XML & JSON 2
F JDOM und XPath - Problem mit Namespace ohne Prefix XML & JSON 5
F JDom und XPath XML & JSON 12
clemson xpath mit jdom XML & JSON 2
Kirby.exe Probleme mit XML XPATH Select XML & JSON 3
B XPath soll XML liefern XML & JSON 7
O XPATH Problem - Anfänger XML & JSON 4
M dom4j unberechtigte Invalid XPath expression XML & JSON 12
W XPath schreiben XML & JSON 1
P HTML XPath XML & JSON 1
S Ersatz für die veraltete Klasse XPath XML & JSON 1
C XPath: Alle Kinder in einer Schleife auslesen XML & JSON 2
P Xpath zugriff auf Attribute XML & JSON 3
P "XPath is deprecated" XML eclipse XML & JSON 3
G HtmlUnit XPath XML & JSON 5
D XPath-Query XML & JSON 2
I XPath Namensräume und auslesen einzelner Knoten XML & JSON 3
AMStyles XPATH Befehl SVG Java XML & JSON 2
G xpath: in Kindelement zwei Attribut-Werte auslesen XML & JSON 2
G xpath: Inhalt eines Kindelements auslesen XML & JSON 2
H ChildNode via XPath ansprechen XML & JSON 2
S Attribute von Elementen auslesen mit XPath XML & JSON 2
W XPath + Inhalt aus <td> XML & JSON 2
R XPath - frage zur Adressierung XML & JSON 3
reibi XPath XML & JSON 14
M xPath liefert leeres Nodeset XML & JSON 2
M Probleme mit XPath bei Java XML & JSON 5
W Element mit XPath @id ermitteln wenn nur ein teil der id bekannt ist XML & JSON 2
F XPath-Problem mit DOM4J XML & JSON 8
T XPath Problem: finden einer Node nach Attributswert XML & JSON 2
O XPATH gesucht XML & JSON 6
G XPATH-Frage XML & JSON 2
L Element manipulieren in einem DOMResult per XPath XML & JSON 10
P XPath und Namespaces XML & JSON 3
G XPath - replace function funktioniert nicht XML & JSON 3
E XPATH-Ausdruck mit not XML & JSON 4
E Wieso liefert dieser XPATH-Ausdruck nicht die richtige Anzahl Treffer? XML & JSON 8
M XPath Ausdruck validieren XML & JSON 2
N XPath Adressierung XML & JSON 7
F XPath frage XML & JSON 4
B Optionaler XPath pfad XML & JSON 2
B XPath frage XML & JSON 2
T Frage zu XQuery (XQJ) / XPath XML & JSON 2
P XPath Problem XML & JSON 2
S Problem mit XPath XML & JSON 4
T Mit XPATH finden und dann änder XML & JSON 2
G XPath gesucht für Tag mit konkretem Content XML & JSON 2
A XPath Problem XML & JSON 2
T Prbolem XPath XML & JSON 2
X Xpath, alle Element die mit "user" beginnen auswäh XML & JSON 2
loadbrain XPath Problem XML & JSON 2
M brauche große XML-Datei für XPath-Tests XML & JSON 4
F hilfe bei xpath-ausdruck XML & JSON 2
K java + xpath -> performanceproblem XML & JSON 9
H Xpath kindelemente auslesen XML & JSON 2
S Xml zurück in xpath wandeln XML & JSON 8
G Frage zu XPath XML & JSON 2
flashfactor Filtern mittels XPATH XML & JSON 4
M XSL/XPath - Nur ersten Wert mit selben Attribut XML & JSON 4
M XPath Problem im Zusammenhang mit document() XML & JSON 2
M Frag zu xsl:when beziehungsweise XPath XML & JSON 3
C xpath funktioniert nicht XML & JSON 5
M XPATH und RSS (Problem namespaces) XML & JSON 7
P nochmal XPath :-) XML & JSON 22
P XPath . XML & JSON 2
T Rekursiver Verzeichniss Baum in XML & XPath XML & JSON 4
Wildcard xpath Parser XML & JSON 8
P JDOM oder SAX XML & JSON 3
Hijo2006 Grundsätzliches zu JDOM 2.x XML & JSON 1
W Kindelemente mit JDOM eines bestimmten Attributes auslesen XML & JSON 6
S JDOM XML Datei darstellen Fehler! XML & JSON 2
S JDom XML ein Element hinzufügen. XML & JSON 1
C JDOM: Value ohne Unterelemente auslesen XML & JSON 1
Z XML Datei mit JDOM einlesen und verarbeiten XML & JSON 6
J JDOM XMLOutputter getPrettyFormat() XML & JSON 3
H JDOM setAttribute Reihenfolge XML & JSON 3
B XML aus einer URL im Internet lesen (JDOM) XML & JSON 4
F Aus XML mit JDOM aus Elementattributen Werte rauslesen XML & JSON 4
R sax, stax, jdom, jaxb? List von Objekten speichern und laden XML & JSON 6
C xml validierung gegen xsd mit jdom: Fehlermeldung Cannot find the declaration of element ... XML & JSON 8
T Dom, Jdom, Sax XML & JSON 8
Helgon MalformedByteSequenceException und null JDOM Attribute XML & JSON 5
Helgon JDOM schreibt nicht XML & JSON 2
A XSl mit JDom auslesen XML & JSON 1
G xml, jdom "Entität wurde referenziert aber nicht deklariert." XML & JSON 4
A XSL und JDom XML & JSON 3
G jdom-Klassen in Eclipse importieren XML & JSON 2
S JDOM ohne XML Header erzeugen? XML & JSON 2
S JDOM nur Attribut Name XML & JSON 2
X JDom für SOAP Dateien geeignet? XML & JSON 3
M XML Parsen JDOM NullPointerEcxeption XML & JSON 7
S jdom hasChildren()? XML & JSON 1
T Frage zu getContent unter jdom XML & JSON 6
Z Tutorial für JDOM (XSD-Shema) XML & JSON 3
D jdom, xml, login-system XML & JSON 4
N JDOM: XML einlesen XML & JSON 4
O Parsen einer XML mit JDOM ohne Doctype Declaration XML & JSON 2

Ähnliche Java Themen

Neue Themen


Oben