[XML-SIG] minidom question...
Brian Gyss
briangy at stanwinston.com
Fri Mar 4 19:56:43 CET 2005
All -
I'm having a small problem when I'm using minidom. Here's a sample of
my XML:
<classads>
<c>
<a n="CpuBusyTime"><i>0</i></a>
<a n="CpuIsBusy"><b v="f"/></a>
<a n="State"><s>Unclaimed</s></a>
<a n="EnteredCurrentState"><i>1109899523</i></a>
<a n="Activity"><s>Idle</s></a>
<a n="EnteredCurrentActivity"><i>1109899826</i></a>
</c>
</classads>
Here's my code:
condorQueueStatus = os.popen('condor_status -xml').read()
# remove all irrelevant fields from condorQueueStatus
x = minidom.parseString(condorQueueStatus)
x.normalize()
# gets the individual classads
classads = x.getElementsByTagName("c")
# match classad names to variables
for ad in classads:
currentParts = ad.getElementsByTagName("a")
for field in currentParts:
attrib = field.getAttribute("n")
if field.childNodes[0].childNodes[0].nodeType ==
field.childNodes[0].childNodes[0].TEXT_NODE:
nodeVal = field.childNodes[0].childNodes[0].nodeValue
print attrib + ": " + nodeVal
if field.childNodes[0].nodeType ==
field.childNodes[0].ATTRIBUTE_NODE:
nodeVal = field.childNodes[0].getAttribute("v")
print attrib + ": " + nodeVal
What I'm basically getting as output is this:
CpuBusyTime:
CpuIsBusy: f
State:
EnteredCurrentState:
Activity:
EnteredCurrentActivity:
However, I would like both the text fields as well as the attribute
field at the same level to be represented in my output. When I try to
print out only the text fields, it prints out up to the first element
with an attribute and then produces this error:
Traceback (most recent call last):
File "./parserTest4.py", line 34, in ?
nodeVal = field.childNodes[0].childNodes[0].nodeValue
IndexError: list index out of range
Does anyone have any suggestions for how I can successfully test for
both the text value and the attribute?
Thanks!
- Brian
More information about the XML-SIG
mailing list