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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T11:38:49+00:00 2026-05-25T11:38:49+00:00

My input file is actually multiple XML files appending to one file. (It’s from

  • 0

My input file is actually multiple XML files appending to one file. (It’s from Google Patents). It has below structure:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE us-patent-grant SYSTEM "us-patent-grant.dtd" [ ]>
<root_node>...</root_node>
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE us-patent-grant SYSTEM "us-patent-grant.dtd" [ ]>
<root_node>...</root_node>
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE us-patent-grant SYSTEM "us-patent-grant.dtd" [ ]>
<root_node>...</root_node>

Python xml.dom.minidom can’t parse this non-standard file. What’s a better way to parse this file? I am not below code has good performance or not.

for line in infile:
  if line == '<?xml version="1.0" encoding="UTF-8"?>': 
    xmldoc = minidom.parse(XMLstring)
  else:
    XMLstring += line
  • 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-25T11:38:49+00:00Added an answer on May 25, 2026 at 11:38 am

    Here’s my take on it, using a generator and lxml.etree. Extracted information purely for example.

    import urllib2, os, zipfile
    from lxml import etree
    
    def xmlSplitter(data,separator=lambda x: x.startswith('<?xml')):
      buff = []
      for line in data:
        if separator(line):
          if buff:
            yield ''.join(buff)
            buff[:] = []
        buff.append(line)
      yield ''.join(buff)
    
    def first(seq,default=None):
      """Return the first item from sequence, seq or the default(None) value"""
      for item in seq:
        return item
      return default
    
    datasrc = "http://commondatastorage.googleapis.com/patents/grantbib/2011/ipgb20110104_wk01.zip"
    filename = datasrc.split('/')[-1]
    
    if not os.path.exists(filename):
      with open(filename,'wb') as file_write:
        r = urllib2.urlopen(datasrc)
        file_write.write(r.read())
    
    zf = zipfile.ZipFile(filename)
    xml_file = first([ x for x in zf.namelist() if x.endswith('.xml')])
    assert xml_file is not None
    
    count = 0
    for item in xmlSplitter(zf.open(xml_file)):
      count += 1
      if count > 10: break
      doc = etree.XML(item)
      docID = "-".join(doc.xpath('//publication-reference/document-id/*/text()'))
      title = first(doc.xpath('//invention-title/text()'))
      assignee = first(doc.xpath('//assignee/addressbook/orgname/text()'))
      print "DocID:    {0}\nTitle:    {1}\nAssignee: {2}\n".format(docID,title,assignee)
    

    Yields:

    DocID:    US-D0629996-S1-20110104
    Title:    Glove backhand
    Assignee: Blackhawk Industries Product Group Unlimited LLC
    
    DocID:    US-D0629997-S1-20110104
    Title:    Belt sleeve
    Assignee: None
    
    DocID:    US-D0629998-S1-20110104
    Title:    Underwear
    Assignee: X-Technology Swiss GmbH
    
    DocID:    US-D0629999-S1-20110104
    Title:    Portion of compression shorts
    Assignee: Nike, Inc.
    
    DocID:    US-D0630000-S1-20110104
    Title:    Apparel
    Assignee: None
    
    DocID:    US-D0630001-S1-20110104
    Title:    Hooded shirt
    Assignee: None
    
    DocID:    US-D0630002-S1-20110104
    Title:    Hooded shirt
    Assignee: None
    
    DocID:    US-D0630003-S1-20110104
    Title:    Hooded shirt
    Assignee: None
    
    DocID:    US-D0630004-S1-20110104
    Title:    Headwear cap
    Assignee: None
    
    DocID:    US-D0630005-S1-20110104
    Title:    Footwear
    Assignee: Vibram S.p.A.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an XML input file and I'm trying to output the result of
When reading data from the Input file I noticed that the ¥ symbom was
This is one line of the input file: FOO BAR 0.40 0.20 0.40 0.50
I am trying to read values from an input file in Perl. Input file
Hope you all will be fine. Actually i want to upload image files from
I have a section of code that I need to remove from multiple files
I am trying to fake a file upload without actually using a file input
My input file's contents are: welcome welcome1 welcome2 My script is: for groupline in
Say I have an input file, and a target directory. How do I determine
I have an input file that I want to sort based on timestamp which

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.