FAQ
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)
line that can be imported to a spreadsheet. Not all elements are in each
line or part of the XML document - so if an element is not in a line, I
would leave a blank (2 commas). I can probably figure that out - it's the
extracting multiple elements and putting them in one line that has me
stumped. Help would be greatly appreciated. Thank you. What I have so
far (and I would like to stick to the DOM model):

import xml.dom.minidom
import sys


datasource=open(sys.argv[1])
domDatasource=xml.dom.minidom.parse(datasource)

def getText(nodelist):
rc=""
for node in nodelist:
if node.nodeType == node.TEXT_NODE:
rc=rc+node.data
return rc

def HandleStatus(Finding):
for Status in Finding:
print getText(Status.childNodes)

HandleStatus (domDatasource.getElementsByTagName("FINDING_STATUS"))

domDatasource.unlink()

An excerpt of the xml file:



</SCRIPT_RESULTS><TOOL>GD</TOOL><TOOL_VERSION>2.0.8.8</TOOL_VERSION><AUTHENTICATED_FINDING>TRUE</AUTHENTICATED_FINDING><GD_VUL_NAME>DTBI134-Allow
paste operations via
scripts-Restric</GD_VUL_NAME><GD_SEVERITY>2</GD_SEVERITY></FINDING><FINDING><FINDING_ID
TYPE="VK">V0006310</FINDING_ID><FINDING_STATUS>NF</FINDING_STATUS><TOOL>GD</TOOL><TOOL_VERSION>2.0.8.8</TOOL_VERSION><AUTHENTICATED_FINDING>TRUE</AUTHENTICATED_FINDING><GD_VUL_NAME>DTBI135-Scripting
of Java applets -
Restricted</GD_VUL_NAME><GD_SEVERITY>2</GD_SEVERITY></FINDING><FINDING><FINDING_ID
TYPE="VK">V0006311</FINDING_ID><FINDING_STATUS>O</FINDING_STATUS><FINDING_DETAILS
OVERRIDE="O">The value:
Software\Policies\Microsoft\Windows\CurrentVersion\Internet
Settings\Zones\4\1A00 does not exist.

</FINDING_DETAILS><SCRIPT_RESULTS>The value:
Software\Policies\Microsoft\Windows\CurrentVersion\Internet
Settings\Zones\4\1A00 does not exist.

</SCRIPT_RESULTS><TOOL>GD</TOOL><TOOL_VERSION>2.0.8.8</TOOL_VERSION><AUTHENTICATED_FINDING>TRUE</AUTHENTICATED_FINDING><GD_VUL_NAME>DTBI136-User
Authentication - Logon -
Restricted</GD_VUL_NAME><GD_SEVERITY>2</GD_SEVERITY></FINDING><FINDING><FINDING_ID
TYPE="VK">V0006312</FINDING_ID><FINDING_STATUS>NF</FINDING_STATUS><TOOL>GD</TOOL><TOOL_VERSION>2.0.8.8</TOOL_VERSION><AUTHENTICATED_FINDING>TRUE</AUTHENTICATED_FINDING><GD_VUL_NAME>DTBI150-Microsoft
Java VM is
installed</GD_VUL_NAME><GD_SEVERITY>2</GD_SEVERITY></FINDING><FINDING><FINDING_ID
TYPE="VK">V0006313</FINDING_ID><FINDING_STATUS>NF</FINDING_STATUS><TOOL>GD</TOOL><TOOL_VERSION>2.0.8.8</TOOL_VERSION><AUTHENTICATED_FINDING>TRUE</AUTHENTICATED_FINDING><GD_VUL_NAME>DTBI151-Cipher
setting for DES 56/56 not
set</GD_VUL_NAME><GD_SEVERITY>2</GD_SEVERITY></FINDING><FINDING><FINDING_ID
TYPE="VK">V0006314</FINDING_ID><FINDING_STATUS>NF</FINDING_STATUS><TOOL>GD</TOOL><TOOL_VERSION>2.0.8.8</TOOL_VERSION><AUTHENTICATED_FINDING>TRUE</AUTHENTICATED_FINDING><GD_VUL_NAME>DTBI152-Cipher
setting for Null is not
set</GD_VUL_NAME><GD_SEVERITY>2</GD_SEVERITY></FINDING><FINDING><FINDING_ID
TYPE="VK">V0006315</FINDING_ID><FINDING_STATUS>NF</FINDING_STATUS><TOOL>GD</TOOL><TOOL_VERSION>2.0.8.8</TOOL_VERSION><AUTHENTICATED_FINDING>TRUE</AUTHENTICATED_FINDING><GD_VUL_NAME>DTBI153-Cipher
setting for Triple DES is not
set</GD_VUL_NAME><GD_SEVERITY>2</GD_SEVERITY></FINDING><FINDING><FINDING_ID
TYPE="VK">V0006316</FINDING_ID><FINDING_STATUS>O</FINDING_STATUS><FINDING_DETAILS
OVERRIDE="O">The value:
SYSTEM\CurrentControlSet\Control\SecurityProviders\SCHANNEL\Hashes\SHA\Enabled
does not exist.

</FINDING_DETAILS><SCRIPT_RESULTS>The value:
SYSTEM\CurrentControlSet\Control\SecurityProviders\SCHANNEL\Hashes\SHA\Enabled
does not exist.

</SCRIPT_RESULTS><TOOL>GD</TOOL><TOOL_VERSION>2.0.8.8</TOOL_VERSION><AUTHENTICATED_FINDING>TRUE</AUTHENTICATED_FINDING><GD_VUL_NAME>DTBI160-Hash
setting for SHA is not set
properly</GD_VUL_NAME><GD_SEVERITY>2</GD_SEVERITY></FINDING><FINDING><FINDING_ID
TYPE="VK">V0006317</FINDING_ID><FINDING_STATUS>NF</FINDING_STATUS><TOOL>GD</TOOL><TOOL_VERSION>2.0.8.8</TOOL_VERSION><AUTHENTICATED_FINDING>TRUE</AUTHENTICATED_FINDING><GD_VUL_NAME>DTBG007-IE
is not capable to use 128-bit
encryptio</GD_VUL_NAME><GD_SEVERITY>2</GD_SEVERITY></FINDING><FINDING><FINDING_ID
TYPE="VK">V0006318</FINDING_ID><FINDING_STATUS>O</FINDING_STATUS><FINDING_DETAILS
OVERRIDE="O">The key:
SOFTWARE\Microsoft\SystemCertificates\Root\Certificates\10F193F340AC91D6DE5F1EDC006247C4F25D9671
does not exist.

</FINDING_DETAILS><SCRIPT_RESULTS>The key:
SOFTWARE\Microsoft\SystemCertificates\Root\Certificates\10F193F340AC91D6DE5F1EDC006247C4F25D9671
does not exist.

</SCRIPT_RESULTS><TOOL>GD</TOOL><TOOL_VERSION>2.0.8.8</TOOL_VERSION><AUTHENTICATED_FINDING>TRUE</AUTHENTICATED_FINDING><GD_VUL_NAME>DTBG010-DoD
Root Certificate is not
installed</GD_VUL_NAME><GD_SEVERITY>2</GD_SEVERITY></FINDING><FINDING><FINDING_ID
TYPE="VK">V0006319</FINDING_ID><FINDING_STATUS>NA</FINDING_STATUS><TOOL>GD</TOOL><TOOL_VERSION>2.0.8.8</TOOL_VERSION><AUTHENTICATED_FINDING>TRUE</AUTHENTICATED_FINDING><GD_VUL_NAME>DTBI140-Error
Reporting tool is installed or
enabl</GD_VUL_NAME><GD_SEVERITY>2</GD_SEVERITY></FINDING><FINDING><FINDING_ID
TYPE="VK">V0007006</FINDING_ID><FINDING_STATUS>O</FINDING_STATUS><FINDING_DETAILS
OVERRIDE="O">The value: Software\Microsoft\Internet
Explorer\Main\AutoSearch does not exist.

</FINDING_DETAILS><SCRIPT_RESULTS>The value: Software\Microsoft\Internet
Explorer\Main\AutoSearch does not exist.

Search Discussions

Discussion Posts

Follow ups

Related Discussions

Discussion Navigation
viewthread | post
posts ‹ prev | 1 of 5 | next ›
Discussion Overview
grouptutor @
categoriespython
postedMar 10, '09 at 11:02p
activeMar 13, '09 at 1:40a
posts5
users4
websitepython.org

People

Translate

site design / logo © 2022 Grokbase