Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8466787
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T15:26:43+00:00 2026-06-10T15:26:43+00:00

I am trying to add a xml file in a dict. Now What i

  • 0

I am trying to add a xml file in a dict. Now What i want to do is to update the value into the dict without losing the value. Reason for this is I want to group the xml file to show all the changes made by the tag author.

Here is a sample of the xml file.

<log> 
<logentry 
revision="33185"> 
<author>glv</author> 
<date>2012-08-06T21:01:52.494219Z</date> 
<paths> 

<path 
kind="file" 
action="M">/branches/Patch_4_2_0_Branch/text.xml</path>    

<path 
kind="dir" 
action="M">/branches/Patch_4_2_0_Branch</path> 

</paths> 
<msg>PATCH_BRANCH:N/A 
BUG_NUMBER:N/A 
FEATURE_AFFECTED:N/A 
OVERVIEW:N/A 
Adding the SVN log size requirement to the branch  
</msg> 
</logentry> 
 .... 
</log> 

Here is the code I have for it written in Python.

from xml.dom import minidom 
import smtplib 
from email.mime.text import MIMEText 
from datetime import datetime 

def xml_data (): 

f = open('C:\opidea_2.xml', 'r') 

data = f.read() 

f.close() 

dom = minidom.parseString(data) 

ic = (dom.getElementsByTagName('logentry')) 

dom = None       
content = '' 
author = {}   
for num in ic: 

authors = num.getElementsByTagName('author') 

if len(authors) > 0: 

  name = authors[0].firstChild.nodeValue 

  author.update({'author': str(name)})  

datef = [] 
xmlDate = num.getElementsByTagName('date')[0].firstChild.nodeValue 
datef = [Good_Time] 
path_change = []  
paths = [x for x in num.getElementsByTagName("paths")[0].childNodes if isinstance(x, minidom.Element)] 

for path in paths:  

  x = path.childNodes[0].nodeValue   

if str(path.getAttribute("kind")) == 'dir': 

  path_change ='Directory location: ' + [str(x)] 
else:  
  path_change ='Filename: ' + [str(x)] 

xmlMsgf = [] 
xmlMsg = num.getElementsByTagName('msg') 


if xmlMsg !='' and len(xmlMsg) > 0: 
  xmlMsgc = xmlMsg[0].firstChild.nodeValue 
  xmlMsgf = [xmlMsgc] 


 else: 
   xmlMsgc = "No comment made." 
   xmlMsgf = [xmlMsgc] 

 authorentry.push{('author',authorA),('date',datef),('path',path_change),('path',xmlMsgf))}           

    for k, v in [(authorentry)]:

        try:

            author[k].append(v)

        except KeyError:

            author[k] = [v]

 author.update({'Date':datef,'Path':path_change,'msg':str(xmlMsgf)}) 
 print author

if __name__ == "__main__": 
  xml_data () 

Now what I want the end result to be is like this

Key 1 = glv , date1 ,path 1a path 1b , msg1 , date2 , path 2 , msg 2 , …

key 2 = jsm , date1 , path 1 , msg 1.

I want to group the author.update({‘Date’:datef,’Path’:path_change,’msg’:str(xmlMsgf)}) to list the xml file by the authors to append the next set of things the author made. Not very sure how to go about that. Any help would be appreciated. Here is my updated code but I seem to now get an invalid syntax error:

  line 151
    authorentry.push{('author',authorA),('date',datef),('path',path_change),('path',xmlMsgf))}           
                    ^
 SyntaxError: invalid syntax
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T15:26:45+00:00Added an answer on June 10, 2026 at 3:26 pm

    You cannot ‘keep old values’ in a dict, each key has exactly one value associated with it.

    You can use aggregate value types in dict’s though, for instance you can use a list as the values, and each time you find a bit of data to add, append it to the associated list.

    data = {}
    
    for k, v in [('a', 1), ('a', 2), ('b', 3)]:
        try:
            data[k].append(v)
        except KeyError:
            data[k] = [v]  # a list of one element!
    

    There’s a convenience constructor in the collections module that can make this even easier:

    import collections
    
    data = collections.defaultdict(list)
    for k, v in [('a', 1), ('a', 2), ('b', 3)]:
        data[k].append(v)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to add all the nodes in an XML file into a listView,
I am now trying to add a simple PE into my app. This PE
I have an XML file I'm trying to modify and want to add a
I am trying to add a tag and it's value dynamically into the xml
I recently databounded an xml file to a listbox. Now I want to write
I'm trying to add FileInfo details to my xml file by recursively scanning and
In java xml file I am trying to add a element to connection node
I am trying to add a processing instructions to my xml file in the
Can anyone please help. I am trying to convert excel data into xml file
I have LinearLayout in my xml file that I am trying to add a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.