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 7414435
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T07:06:00+00:00 2026-05-29T07:06:00+00:00

I have a csv file that contains XML entries. Imagine that each XML entry

  • 0

I have a csv file that contains XML entries. Imagine that each XML entry starts with <entry> and ends with </entry>. There are thousands of these entries in my file. Each XML entry consists of nested XML elements.

I need to extract some elements of each entry and save them into another file by Python. Here is a sample of one XML entry. Imagine that I want to extract and elements of each entry. could you please advise me how I can do this in Python? I’m a beginner in Python programming.

"<entry xmlns=""http://www.w3.org/2005/Atom"" xmlns:gnip=""http://www.gnip.com/schemas/2010"">
  <id>tag:search.twitter.com,2005:157796632933576704</id>
  <published>2012-01-13T12:10:23+00:00</published>
  <updated>2012-01-13T12:10:23+00:00</updated>
  <summary type=""html"">RT @sprice54: If you rearrange the words ""Debit card"" you can spell ""Bad Credit""</summary>
  <link rel=""alternate"" type=""text/html"" href=""http://twitter.com/GCordivari/statuses/157796632933576704""/>
  <source>
    <link rel=""self"" type=""application/json"" href=""https://stream.twitter.com/1/statuses/filter.json""/>
    <title>Twitter - Stream - Track</title>
    <updated>2012-01-13T12:10:25Z</updated>
  </source>
  <service:provider xmlns:service=""http://activitystrea.ms/service-provider"">
    <name>Twitter</name>
    <uri>http://www.twitter.com/</uri>
    <icon/>
  </service:provider>
  <contributor>
    <name>Steve Price</name>
    <uri>http://www.twitter.com/sprice54</uri>
  </contributor>
  <link rel=""via"" type=""text/html"" href=""http://twitter.com/sprice54/statuses/157748462321012736""/>
  <title>George Cordivari shared: Steve Price posted a note on Twitter</title>
  <category term=""StatusShared"" label=""Status Shared""/>
  <category term=""NoteShared"" label=""Note Shared""/>
  <activity:verb xmlns:activity=""http://activitystrea.ms/spec/1.0/"">http://activitystrea.ms/schema/1.0/share</activity:verb>
  <activity:object xmlns:activity=""http://activitystrea.ms/spec/1.0/"">
    <activity:object-type>http://activitystrea.ms/schema/1.0/note</activity:object-type>
    <id>object:search.twitter.com,2005:157796632933576704</id>
    <content type=""html"">RT @sprice54: If you rearrange the words ""Debit card"" you can spell ""Bad Credit""</content>
    <link rel=""alternate"" type=""text/html"" href=""http://twitter.com/GCordivari/statuses/157796632933576704""/>
  </activity:object>
  <author>
    <name>George Cordivari</name>
    <uri>http://www.twitter.com/GCordivari</uri>
  </author>
  <activity:author xmlns:activity=""http://activitystrea.ms/spec/1.0/"">
    <activity:object-type>http://activitystrea.ms/schema/1.0/person</activity:object-type>
    <gnip:friends xmlns:gnip=""http://www.gnip.com/schemas/2010"" followersCount=""37"" followingCount=""61""/>
    <link rel=""alternate"" type=""text/html"" length=""0"" href=""http://www.twitter.com/GCordivari""/>
    <link rel=""avatar"" href=""http://a0.twimg.com/profile_images/1670548060/274805_1268643462_1179159089_n_normal.jpg""/>
    <id>http://www.twitter.com/GCordivari</id>
  </activity:author>
  <activity:actor xmlns:activity=""http://activitystrea.ms/spec/1.0/"">
    <activity:object-type>http://activitystrea.ms/schema/1.0/person</activity:object-type>
    <gnip:friends xmlns:gnip=""http://www.gnip.com/schemas/2010"" followersCount=""37"" followingCount=""61""/>
    <gnip:stats xmlns:gnip=""http://www.gnip.com/schemas/2010"" activityCount=""370"" upstreamId=""id:twitter.com:427031045""/>
    <link rel=""alternate"" type=""text/html"" length=""0"" href=""http://www.twitter.com/GCordivari""/>
    <link rel=""avatar"" href=""http://a0.twimg.com/profile_images/1670548060/274805_1268643462_1179159089_n_normal.jpg""/>
    <id>http://www.twitter.com/GCordivari</id>
    <os:location xmlns:os=""http://ns.opensocial.org/2008/opensocial"">Drexel Hell</os:location>
    <os:aboutMe xmlns:os=""http://ns.opensocial.org/2008/opensocial"">This is the way I live. #CirocInMyCupIDGAF #CloudNine  #FollowMeLikeTheLeader </os:aboutMe>
  </activity:actor>
  <gnip:twitter_entities xmlns:gnip=""http://www.gnip.com/schemas/2010"">
    <user_mentions>
      <user_mention start=""3"" end=""12"">
        <id>255347428</id>
        <name>Steve Price</name>
        <screen_name>sprice54</screen_name>
      </user_mention>
    </user_mentions>
  </gnip:twitter_entities>
  <gnip:matching_rules>
    <gnip:matching_rule rel=""inferred"">""debit card""</gnip:matching_rule>
  </gnip:matching_rules>
</entry>"
  • 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-05-29T07:06:01+00:00Added an answer on May 29, 2026 at 7:06 am

    Following the examples in the docs here is how you could extract all named elements, say contributors and export them to a new XML document.

    import xml.dom.minidom as minidom
    
    #open the input csv/xml file
    inputPath = '/path/to/xml.csv'
    xml_csv = open(inputPath)
    
    #open a output file in write mode
    outputPath = '/path/to/contributors.xml'
    outxml = open(outputPath,'w')
    
    #create a new xml document and top level element
    impl = minidom.getDOMImplementation()
    newxml = impl.createDocument(None,'contributors',None)
    top = newxml.documentElement
    
    #loop through each line in the file splitting on commas
    for line in xml_csv:
        xmlFields = line.split(',')
    
        for fldxml in xmlFields:
            #double double quotes caused the parser to choke, I'm replacing them here
            fldxml = fldxml.replace('""','"')
    
            #parse the xml data from each field and 
            #find all contributor elements under the top level
            dom = minidom.parseString(xmlfld)
            contributors = entry.getElementByTagName('contributor')
    
            #add each contributor to the new xml document
            for contributor in contributors:
                top.appendChild(contributor)
    
    #write out the new xml contributors document in pretty XML
    outxml.write(newxml.toprettyxml())
    outxml.close()
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a file that contains the following in a csv file; country,region,city,postalCode,metroCode,areaCode I
I have a Testing project that contains a csv file which a webtest uses
I have a CSV file that contains over 80,000 rows and 100 columns. I'm
I have a VB web application that reads from a CSV file which contains
I have a csv file that contains a location field. I need to import
Hi i have a CSV file that contains rows like this Jacop , Assistant,150,75
I have a large CSV file that contains independent items that take a fair
I have a csv file that contains the following values Spam2,pank,Spam3,Spam6,Spam7 Spam1,Spam5,Spam0,Spam9 And i
I have a CSV (comma separated values) file that contains student information. The column
I have an Excel (or CSV) file that contains the following flattened columns: ID,XPath,Required?,BaseType,Restrictions

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.