I'm a little bored, so I wrote a function that gets elements
and puts them in a dictionary. Missing elements are just an empty
string.
http://gist.github.com/78385
Usage:
>>> d = process_finding(findings[0])
>>> ", ".join(map(lambda e: d[e], elements))
u'V0006310, NF, , , GD, 2.0.8.8, TRUE, DTBI
So you want one line for each element? Easy:
# Get elements
findings = domDatasource.getElementsByTagName('FINDING')
# Get the text of all direct child nodes in each element
# That's assuming every child has a TEXT_NODE node.
lines = []
for finding in findings:
lines.append([f.firstChild.d
On Thu, Mar 12, 2009 at 08:47:24PM +0100, Stefan Behnel wrote:
> m...@marcd.org wrote:
[snip]
>
> There is another "DOM Model" in the stdlib. It's called ElementTree and is
> generally a lot easier to use. For example, to find the text content of an
> element called "element_that_has_text_content
m...@marcd.org wrote:
> I am new to Python and as a first project decided to try to parse an XML
> report using Python. I have the following, which works to extract one
> element. I am stuck, however, at one element. I want to extract several
> differenct elements per line, creating a comma sepa
Hello,
I am new to Python and as a first project decided to try to parse an XML
report using Python. I have the following, which works to extract one
element. I am stuck, however, at one element. I want to extract several
differenct elements per line, creating a comma separated variable (CSV)
l