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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T10:09:17+00:00 2026-06-08T10:09:17+00:00

Trying to parse xml to text I got something like this, INPUT FILE <Item

  • 0

Trying to parse xml to text I got something like this,

INPUT FILE

<Item id="1"></Item>
<Item id="2"></Item>
<Item id="1"></Item>
<Item id="2"></Item>

CURRENT OUTPUT

 Item ->1
 Item ->2
 Item ->2
 Item ->1

My DESIRED OUTPUT would be,

Item ->1
Item ->2

(Ignoring repeated id values)

The current code I’m using to obtain my CURRENT OUTPUT is,

list = node.getElementsByTagName('Item')
for item in list:
  output_id = item.getAttribute('id')
  print "Item ->", output_id

I’ve tried thousands of list remove methods but they all output the double ids. Help would be greatly appreciated.
Tks

  • 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-08T10:09:18+00:00Added an answer on June 8, 2026 at 10:09 am

    At first, every DOM parser will return doubled ids as they’re different elements.
    To avoid, go through dom tree and store results in dict object. This will get you only last items.

    UPD:

    list = node.getElementsByTagName('Item')
    items = {}
    for item in list:
      output_id = item.getAttribute('id')
      items[output_id] = item # Put items into dict to use them later.
    for id in items:
      print "Item[%d] -> %s" % (id, items[id]) # Only single item per id left.
    

    And more ‘pythonic’ way:

    list = node.getElementsByTagName('Item')
    items = dict((item.getAttribute('id'), item) for item in list)
    for id in items:
      print "Item[%d] -> %s" % (id, items[id]) # Only single item per id left.
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to parse xml done like this: <foreign lang=gre>&lsquo;<LM lemma=auieo catg=fg>auieo</LM>&rsquo;</foreign> I'm using
i am trying to parse this xml file into an object to use the
Here is a snippet from the XML file I am trying to parse: <Item
I'm trying to parse an xml file output from googletest to display the results
Trying to parse some XML but apparently this is too much for a lazy
I am trying to parse specific XML file which is located in sub directories
I'm trying to parse this XML I want to get a list of all
I am trying to parse an XML file with python using lxml, but get
I'm trying to parse data from Archive.org's search functionality. The data looks like this:
I am trying to parse a large XML file using JavaScript. Looking online, it

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.