I am currently finishing up on a program that is suppose to parse a xml file and then set it up and then email it. I am almost done with it but I appear to be stuck and could use some assistance. I am trying to get the path attribute “dir” and “file” from the completed dictionary but i am getting a error with it. Here is part of the code that I am currently working on.
Update: I added the dictonary telling me if it its a Directory change or a Filename change a list along side the
def formatChangesByAuthor(changesByAuthor):
content = ''
for author, changes in sorted(changesByAuthor.iteritems()):
authorName = get_author_name( author );
content += ' ***** Changes By '+authorName+'*****\n\n'
for change in changes:
rawDate = change['date']
dateRepresentation = rawDate.strftime("%m/%d/%Y %I:%M:%S %p")
content += ' Date: '+ dateRepresentation+'\n\n'
path_change = change['paths']
path_attribute= change['Attribute_changes']
finalizedPathInformation = []
for single_change in path_change:
for single_output in path_attribute:
finalizedPathInformation.append(single_output+single_change)
content +=" " + str(finalizedPathInformation) + "\n"
What I am hoping to get to work is when there are multiple path in paths it will do
filename : test.xml
directory location : /Testforlder/
for some reason it is showing me a memory error. I wonder if i could of wrote the path part better. Here is my error I am getting.
content +=" " + str(finalizedPathInformation) + "\n" MemoryError
Now here is part of the xml file if it will help.
<log>
<logentry
revision="33185">
<author>glv</author>
<date>2012-08-06T21:01:52.494219Z</date>
<paths>
<path
action="M"
kind="file">/trunk/build.xml</path>
<path
kind="dir"
action="M">/trunk</path>
</paths>
<msg>PATCH_BRANCH:N/A
BUG_NUMBER:N/A
FEATURE_AFFECTED:N/A
OVERVIEW:N/A
Testing the system log.
</msg>
</log>
Now i had the nodeValue saved in the dictionary but for some reason I can’t to get the attribute within the nodeValue to see if it has a “dir” or a “file” attribute at all. I am pretty sure I am doing something wrong somewhere. Any advice or help would be very appreciated and welcomed 🙂
Obviously your
path_changeis a list. Trypath_change[0].getAttribute('kind').I also propose to add debug output (
print path_changebefore the call of getAttribute()) to find out more about your data structures.Of course if there’s a list you might want to process all elements in the list, not just the first. One way to do this could be: