Seite 1 von 1

2D Liste als HTML-Tabelle in XML Datei auslesen

Verfasst: Mittwoch 24. Mai 2006, 16:21
von keboo
Hallo Leute!

Wie kann ich eine 2D Liste (HTML Format) in ein XML Datei auslesen?

Code: Alles auswählen

table=[['row1','row2','row3'],[1,2,3],[1,2,3],[1,2,3],[1,2,3],[1,2,3]]

Welche Methoden gibt es in Python, diese Liste im HTML Code für Tabellen in ein XML File zu auszulesen?

Danke,

Johannes :)

Re: 2D Liste als HTML-Tabelle in XML Datei auslesen

Verfasst: Mittwoch 24. Mai 2006, 17:46
von gerold
keboo hat geschrieben:Welche Methoden gibt es in Python, diese Liste im HTML Code für Tabellen in ein XML File zu auszulesen?
Hi Johannes!

Willst du diese Liste als HTML oder als XML? Ich verstehe deine Frage nicht.

mfg
Gerold
:-)

Verfasst: Mittwoch 24. Mai 2006, 19:38
von keboo
hi gerold!

Ich möchte die Tabelle für DocBOOK-XML vorbereiten.
In einem Manual dafür hab ich gelesen, dass das HTML Format für Tabellen lesbar ist.

Es ist quasi für eine XML Datei, die ich mich DocBOOK dann weiterverabeiten möchte.

Ich hoffe, dass es jetzt besser verständlich ist. Sorry für die unklare Frage.

Johannes

Verfasst: Mittwoch 24. Mai 2006, 20:02
von gerold
keboo hat geschrieben:Johannes
Hi Johannes!

Suchst du so etwas?

Code: Alles auswählen

table = [
    ['row1','row2','row3'],
    [1,2,3],
    [1,2,3],
    [1,2,3],
    [1,2,3],
    [1,2,3]
]

#
# Variante 1 (print)
#
print "<table>"
#Kopf
print "  <tr>"
for col in table[0]:
    print "    <th>%s</th>" % col
print "  </tr>"
#Daten
for row in table[1:]:
    print "  <tr>"
    for col in row:
        print "    <td>%s</td>" % col
    print "  </tr>"
print "</table>"

#
# Variante 2 (Liste)
#
ret = []
ret.append("<table>")
#Kopf
ret.append("  <tr>")
for col in table[0]:
    ret.append("    <th>%s</th>" % col)
ret.append("  </tr>")
#Daten
for row in table[1:]:
    ret.append("  <tr>")
    for col in row:
        ret.append("    <td>%s</td>" % col)
    ret.append("  </tr>")
ret.append("</table>")

print "\n".join(ret)

Code: Alles auswählen

<table>
  <tr>
    <th>row1</th>
    <th>row2</th>
    <th>row3</th>
  </tr>
  <tr>
    <td>1</td>
    <td>2</td>
    <td>3</td>
  </tr>
  <tr>
    <td>1</td>
    <td>2</td>
    <td>3</td>
  </tr>
  <tr>
    <td>1</td>
    <td>2</td>
    <td>3</td>
  </tr>
  <tr>
    <td>1</td>
    <td>2</td>
    <td>3</td>
  </tr>
  <tr>
    <td>1</td>
    <td>2</td>
    <td>3</td>
  </tr>
</table>
mfg
Gerold
:-)

PS: Mit DocbookXML habe ich nichts am Hut.

Verfasst: Mittwoch 24. Mai 2006, 21:23
von keboo
Danke! Sowas suchte ich!
Lg,
Johannes