Wenn du dir nicht sicher bist, in welchem der anderen Foren du die Frage stellen sollst, dann bist du hier im Forum für allgemeine Fragen sicher richtig.
Ich möchte z.B. mit SAX die Datei einlesen und in eine geeignete Struktur speichern.
1.)
Wie würde eine geeignete Struktur aussehen um über alle Dateien (File) in Sources mit einer for-Schleife durchlaufen zu können und einen Zugang zur MinValue und MaxValue der aktuellen Dateien haben?
2.)
Analog zur 1 nur für Targets.
3.)
Wie könnte man den Path jeder Datei zuweisen z.B. test/B/B002?
Leider habe ich nicht der gleichen im Internet finden können.
@mit: Wie soll denn die Datenstruktur aussehen, mit der Du gerne Arbeiten möchtest? Wenn Du die hast, brauchst Du nur noch Code schreiben der das XML in diese Struktur umwandelt.
Wie die Struktur die Du haben möchtest aussieht, kannst nur Du sagen, denn Du musst damit am Ende ja arbeiten.
Von SAX würde ich die Finger lassen und `lxml` verwenden. Mittels XPath kann man da ganz gut die Knoten beschreiben, die man gerne hätte.
for targetFile in Targets:
print Name # z.B. test1
tfile = TargetPath + TargetFile # z.B. test/t/test1
for Source in Sources:
for sourceFile in Source:
print Name # z.B. B
sourceFile = sourcePath + sourceFile # z.b. test/B/B002
cmd = "pragramm " + tfile + sourceFile + MinValue + MaxValue + APP.Parameters
print cmd # z.B. programm test/t/test1 test/B/B002 200 330 -x 6
@BlackJack: Du hast recht, dass es nicht eindeutig ist. Der Wert ist der Dateiname und das Attribut eine kurze Beschreibung der Datei. Ich den xml Eintrag wie folgt geändert.
for targetFile in Targets:
print Description # z.B. test1
tfile = TargetPath + TargetFile # z.B. test/t/AA2.txt
for Source in Sources:
for sourceFile in Source:
print Name # z.B. B
sourceFile = sourcePath + sourceFile # z.b. test/B/B002
cmd = "pragramm " + tfile + sourceFile + MinValue + MaxValue + APP.Parameters
print cmd # z.B. programm test/t/AA2.txt test/B/B002 200 330 -x 6
Dav1d hat geschrieben:Ich finde lxml auch gut, allerdings reicht mir für 80% der "etree" aus der Std-Bibilothel [mod]xml.etree.elementtree[/mod] bzw. der cElementTree
Der scheitert schon an CSS/XPath, als das was ich in 90% aller Fälle nutzen will.
My god, it's full of CARs! | Leonidasvoice vs (former) Modvoice
$python xml.py
Traceback (most recent call last):
File "xml.py", line 5, in <module>
from lxml import etree
ImportError: /home/mit/programs/python/lib/python2.6/site-packages/lxml-2.2.6-py2.6-linux-x86_64.egg/lxml/etree.so: symbol xmlSchematronSetValidStructuredErrors, version LIBXML2_2.6.32 not defined in file libxml2.so.2 with link time reference
$python
Python 2.6.4 (r264:75706, Jan 28 2010, 14:19:59)
[GCC 4.1.2 20071124 (Red Hat 4.1.2-42)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import lxml
>>>
Ich vermute mal er versucht die falsche libxml2.so.2 zu laden. Was gibt er aus wenn du ``ldd /home/mit/programs/python/lib/python2.6/site-packages/lxml-2.2.6-py2.6-linux-x86_64.egg/lxml/etree.so`` eingibst?
My god, it's full of CARs! | Leonidasvoice vs (former) Modvoice
$ldd /home/mit/programs/python/lib/python2.6/site-packages/lxml-2.2.6-py2.6-linux-x86_64.egg/lxml/etree.so
/home/mit/programs/python/lib/python2.6/site-packages/lxml-2.2.6-py2.6-linux-x86_64.egg/lxml/etree.so: /usr/lib64/libxslt.so.1: no version information available (required by /home/mit/programs/python/lib/python2.6/site-packages/lxml-2.2.6-py2.6-linux-x86_64.egg/lxml/etree.so)
/home/mit/programs/python/lib/python2.6/site-packages/lxml-2.2.6-py2.6-linux-x86_64.egg/lxml/etree.so: /usr/lib64/libxslt.so.1: no version information available (required by /home/mit/programs/python/lib/python2.6/site-packages/lxml-2.2.6-py2.6-linux-x86_64.egg/lxml/etree.so)
/home/mit/programs/python/lib/python2.6/site-packages/lxml-2.2.6-py2.6-linux-x86_64.egg/lxml/etree.so: /usr/lib64/libxslt.so.1: no version information available (required by /home/mit/programs/python/lib/python2.6/site-packages/lxml-2.2.6-py2.6-linux-x86_64.egg/lxml/etree.so)
/home/mit/programs/python/lib/python2.6/site-packages/lxml-2.2.6-py2.6-linux-x86_64.egg/lxml/etree.so: /usr/lib64/libxslt.so.1: no version information available (required by /home/mit/programs/python/lib/python2.6/site-packages/lxml-2.2.6-py2.6-linux-x86_64.egg/lxml/etree.so)
/home/mit/programs/python/lib/python2.6/site-packages/lxml-2.2.6-py2.6-linux-x86_64.egg/lxml/etree.so: /usr/lib64/libxslt.so.1: no version information available (required by /home/mit/programs/python/lib/python2.6/site-packages/lxml-2.2.6-py2.6-linux-x86_64.egg/lxml/etree.so)
/home/mit/programs/python/lib/python2.6/site-packages/lxml-2.2.6-py2.6-linux-x86_64.egg/lxml/etree.so: /usr/lib64/libxslt.so.1: no version information available (required by /home/mit/programs/python/lib/python2.6/site-packages/lxml-2.2.6-py2.6-linux-x86_64.egg/lxml/etree.so)
/home/mit/programs/python/lib/python2.6/site-packages/lxml-2.2.6-py2.6-linux-x86_64.egg/lxml/etree.so: /usr/lib64/libxslt.so.1: no version information available (required by /home/mit/programs/python/lib/python2.6/site-packages/lxml-2.2.6-py2.6-linux-x86_64.egg/lxml/etree.so)
/home/mit/programs/python/lib/python2.6/site-packages/lxml-2.2.6-py2.6-linux-x86_64.egg/lxml/etree.so: /usr/lib64/libxml2.so.2: no version information available (required by /home/mit/programs/python/lib/python2.6/site-packages/lxml-2.2.6-py2.6-linux-x86_64.egg/lxml/etree.so)
/home/mit/programs/python/lib/python2.6/site-packages/lxml-2.2.6-py2.6-linux-x86_64.egg/lxml/etree.so: /usr/lib64/libxml2.so.2: no version information available (required by /home/mit/programs/python/lib/python2.6/site-packages/lxml-2.2.6-py2.6-linux-x86_64.egg/lxml/etree.so)
/home/mit/programs/python/lib/python2.6/site-packages/lxml-2.2.6-py2.6-linux-x86_64.egg/lxml/etree.so: /usr/lib64/libxml2.so.2: no version information available (required by /home/mit/programs/python/lib/python2.6/site-packages/lxml-2.2.6-py2.6-linux-x86_64.egg/lxml/etree.so)
/home/mit/programs/python/lib/python2.6/site-packages/lxml-2.2.6-py2.6-linux-x86_64.egg/lxml/etree.so: /usr/lib64/libxml2.so.2: no version information available (required by /home/mit/programs/python/lib/python2.6/site-packages/lxml-2.2.6-py2.6-linux-x86_64.egg/lxml/etree.so)
/home/mit/programs/python/lib/python2.6/site-packages/lxml-2.2.6-py2.6-linux-x86_64.egg/lxml/etree.so: /usr/lib64/libxml2.so.2: no version information available (required by /home/mit/programs/python/lib/python2.6/site-packages/lxml-2.2.6-py2.6-linux-x86_64.egg/lxml/etree.so)
/home/mit/programs/python/lib/python2.6/site-packages/lxml-2.2.6-py2.6-linux-x86_64.egg/lxml/etree.so: /usr/lib64/libxml2.so.2: no version information available (required by /home/mit/programs/python/lib/python2.6/site-packages/lxml-2.2.6-py2.6-linux-x86_64.egg/lxml/etree.so)
/home/mit/programs/python/lib/python2.6/site-packages/lxml-2.2.6-py2.6-linux-x86_64.egg/lxml/etree.so: /usr/lib64/libxml2.so.2: no version information available (required by /home/mit/programs/python/lib/python2.6/site-packages/lxml-2.2.6-py2.6-linux-x86_64.egg/lxml/etree.so)
/home/mit/programs/python/lib/python2.6/site-packages/lxml-2.2.6-py2.6-linux-x86_64.egg/lxml/etree.so: /usr/lib64/libxml2.so.2: no version information available (required by /home/mit/programs/python/lib/python2.6/site-packages/lxml-2.2.6-py2.6-linux-x86_64.egg/lxml/etree.so)
/home/mit/programs/python/lib/python2.6/site-packages/lxml-2.2.6-py2.6-linux-x86_64.egg/lxml/etree.so: /usr/lib64/libxml2.so.2: no version information available (required by /home/mit/programs/python/lib/python2.6/site-packages/lxml-2.2.6-py2.6-linux-x86_64.egg/lxml/etree.so)
/home/mit/programs/python/lib/python2.6/site-packages/lxml-2.2.6-py2.6-linux-x86_64.egg/lxml/etree.so: /usr/lib64/libxml2.so.2: no version information available (required by /home/mit/programs/python/lib/python2.6/site-packages/lxml-2.2.6-py2.6-linux-x86_64.egg/lxml/etree.so)
/home/mit/programs/python/lib/python2.6/site-packages/lxml-2.2.6-py2.6-linux-x86_64.egg/lxml/etree.so: /usr/lib64/libxml2.so.2: no version information available (required by /home/mit/programs/python/lib/python2.6/site-packages/lxml-2.2.6-py2.6-linux-x86_64.egg/lxml/etree.so)
/home/mit/programs/python/lib/python2.6/site-packages/lxml-2.2.6-py2.6-linux-x86_64.egg/lxml/etree.so: /usr/lib64/libxml2.so.2: no version information available (required by /home/mit/programs/python/lib/python2.6/site-packages/lxml-2.2.6-py2.6-linux-x86_64.egg/lxml/etree.so)
/home/mit/programs/python/lib/python2.6/site-packages/lxml-2.2.6-py2.6-linux-x86_64.egg/lxml/etree.so: /usr/lib64/libxml2.so.2: no version information available (required by /home/mit/programs/python/lib/python2.6/site-packages/lxml-2.2.6-py2.6-linux-x86_64.egg/lxml/etree.so)
/home/mit/programs/python/lib/python2.6/site-packages/lxml-2.2.6-py2.6-linux-x86_64.egg/lxml/etree.so: /usr/lib64/libxml2.so.2: no version information available (required by /home/mit/programs/python/lib/python2.6/site-packages/lxml-2.2.6-py2.6-linux-x86_64.egg/lxml/etree.so)
/home/mit/programs/python/lib/python2.6/site-packages/lxml-2.2.6-py2.6-linux-x86_64.egg/lxml/etree.so: /usr/lib64/libxml2.so.2: no version information available (required by /home/mit/programs/python/lib/python2.6/site-packages/lxml-2.2.6-py2.6-linux-x86_64.egg/lxml/etree.so)
/home/mit/programs/python/lib/python2.6/site-packages/lxml-2.2.6-py2.6-linux-x86_64.egg/lxml/etree.so: /usr/lib64/libxml2.so.2: no version information available (required by /home/mit/programs/python/lib/python2.6/site-packages/lxml-2.2.6-py2.6-linux-x86_64.egg/lxml/etree.so)
/home/mit/programs/python/lib/python2.6/site-packages/lxml-2.2.6-py2.6-linux-x86_64.egg/lxml/etree.so: /usr/lib64/libxml2.so.2: no version information available (required by /home/mit/programs/python/lib/python2.6/site-packages/lxml-2.2.6-py2.6-linux-x86_64.egg/lxml/etree.so)
libxslt.so.1 => /usr/lib64/libxslt.so.1 (0x00002b6c90034000)
libexslt.so.0 => /usr/lib64/libexslt.so.0 (0x00002b6c90269000)
libxml2.so.2 => /usr/lib64/libxml2.so.2 (0x00002b6c9047b000)
libz.so.1 => /usr/lib64/libz.so.1 (0x00002b6c907b9000)
libm.so.6 => /lib64/libm.so.6 (0x00002b6c909cd000)
libpthread.so.0 => /lib64/libpthread.so.0 (0x00002b6c90c50000)
libc.so.6 => /lib64/libc.so.6 (0x00002b6c90e6b000)
libgcrypt.so.11 => /usr/lib64/libgcrypt.so.11 (0x00002b6c911bf000)
libgpg-error.so.0 => /usr/lib64/libgpg-error.so.0 (0x00002b6c9140b000)
libdl.so.2 => /lib64/libdl.so.2 (0x00002b6c9160f000)
/lib64/ld-linux-x86-64.so.2 (0x0000003501c00000)
libnsl.so.1 => /lib64/libnsl.so.1 (0x00002b6c91813000)
Ich glaube du hast recht, aber leider weiss ich nicht wie man es beheben könnte.
$python
Python 2.6.4 (r264:75706, Jan 28 2010, 14:19:59)
[GCC 4.1.2 20071124 (Red Hat 4.1.2-42)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> from lxml import etree
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: /home/mit/programs/python/lib/python2.6/site-packages/lxml-2.2.6-py2.6-linux-x86_64.egg/lxml/etree.so: symbol xmlSchematronSetValidStructuredErrors, version LIBXML2_2.6.32 not defined in file libxml2.so.2 with link time reference
>>>