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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T14:53:48+00:00 2026-05-12T14:53:48+00:00

To parse an input text file and generate a) an XML file and b)

  • 0

To parse an input text file and generate a) an XML file and b) an SVG (also XML) file.

The input text file (input.txt) contains the description of a number of produce distribution centers and storage centers around the country. Each line describes either a single distribution center (dcenter) or a storage center, each with a number of properties; each property name (code for example) is separated by its value with a =.

Example (input.txt)

dcenter: code=d1, loc=San Jose, x=100, y=100, ctype=ct1
dcenter: code=d2, loc=San Ramon, x=300, y=200, ctype=ct2
storage: code=s1, locFrom=d1, x=50, y=50, rtype=rt1
storage: code=s2, locFrom=d1, x=-50,y=100, rtype=rt1

The desired Output of the program:

Output 1

<?xml version="1.0"?>
<dcenters>
<dcenter code="d1">
<loc> San Jose </loc>
<x> 100 </x>
<y> 100 </y>
<ctype> ct1 </ctype>
</dcenter>
<storage code="S1">
<locFrom> d1 </locFrom>
<x> 150 </x>
<y> 150 </y>
<rtype> rt1 </rtype>
</storage>
<storage code="S2">
<locFrom> d1 </locFrom>
<x> 50 </x>
<y> 200 </y>
<rtype> rt1 </rtype>
</storage>

Please help me with the program. I will really appreciate.

  • 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-12T14:53:48+00:00Added an answer on May 12, 2026 at 2:53 pm

    Suppose the input is in string s; either from direct assignment or from file.read:

    s="""dcenter: code=d1, loc=San Jose, x=100, y=100, ctype=ct1
    dcenter: code=d2, loc=San Ramon, x=300, y=200, ctype=ct2
    storage: code=s1, locFrom=d1, x=50, y=50, rtype=rt1
    storage: code=s2, locFrom=d1, x=-50,y=100, rtype=rt1"""
    

    Then you can this:

    print '<?xml version="1.0"?>'
    print "<dcenters>"
    for line in s.splitlines():
        type, fields = line.split(":")
        params = fields.split(",")
        code = params[0].split("=")[1].strip()
        print '<%s code="%s">' % (type, code)
        for p in params[1:]:
            ptype, pvalue = p.strip().split("=")
            print '<%s> %s </%s>' % (ptype, pvalue, ptype)
        print '</%s>' % type
    print "</dcenters>"
    

    Not sure why d2 is missing from your sample output; I assume that’s by mistake.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Ive managed to parse the entire contents of a given input text file and
In Java, I am trying to parse an HTML file that contains complex text
I am trying to read from a text file and tokenize the input. I
if __name__=='__main__': parser = OptionParser() parser.add_option(-i, --input_file, dest=input_filename, help=Read input from FILE, metavar=FILE) (options,
I want to parse a config file sorta thing, like so: [KEY:Value] [SUBKEY:SubValue] Now
I'm trying to parse an INI file using C++. Any tips on what is
We use SAX to parse XML because it does not require the entire XML
Currently my application takes in a text file/files, parses them into another file type
For my data structures class, the first project requires a text file of songs
there is a way by which we parse any time input given by user...

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.