ich möchte wissen, wie ich einen String zwischen einem Tag auslesen kann.
Also quasi: <name>Egon</name>, wie bekomm ich da "Egon" raus?
Mit einem Attribut geht das ja ganz einfach mit node.getAttribute("name"). Allerdings gibt es keine deratige Methode wie z. B. node.getValue(). Mit node.data bekomme ich nur einen leeren String zurück.
XML:
Code: Alles auswählen
<?xml version="1.0" encoding="UTF-8"?>
<table name="logfile">
<row>
<idlogfile>
1
</idlogfile>
<ip>
172.18.222.2
</ip>
<user>
hans
</user>
<time>
2009-01-20 23:53:53
</time>
<method>
GET
</method>
<uri>
/VirtualHostBase/http//bla.de/VirtualHostRoot/
</uri>
<protocol>
HTTP/1.1
</protocol>
<status>
200
</status>
<size>
39738
</size>
</row>
</table>
Code: Alles auswählen
from xml.dom import minidom as dom
from xml.dom import Node
table = dom.parse("logfiles.xml").getElementsByTagName("table")
if len(table) > 0:
table = table[0]
for row in table.childNodes:
if row.nodeName[0] != "#":
for content in row.childNodes:
if content.nodeType == Node.TEXT_NODE:
print content.data
# Funktioniert nicht, gibt nur leeren String zurück..
Mit freundlichen Grüßen