Skip to content

Instantly share code, notes, and snippets.

@theharshbhatia
Created October 6, 2013 11:23
Show Gist options
  • Select an option

  • Save theharshbhatia/6852803 to your computer and use it in GitHub Desktop.

Select an option

Save theharshbhatia/6852803 to your computer and use it in GitHub Desktop.

Revisions

  1. @hash113 hash113 created this gist Oct 6, 2013.
    24 changes: 24 additions & 0 deletions xml2json.py
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,24 @@
    # XML to json converter ...
    #can be modified to change the format
    # by Hash 113
    f=open("quotes.xml","r")
    e=open("Data.txt","w")
    i=0
    for line in f:
    if len(line)>13:
    line=line.lstrip()
    line=line.rstrip()
    s=len(line)
    if line[0:8]=="<author>":
    home=line.index('>')
    end=line.index('/')
    author=line[home+1:end-1]
    elif line[0:7]=="<quote>":
    home=line.index('>')
    end=line.index('/')
    quote=line[home+1:end-1]
    final="lines["+str(i)+"]={ quote:" +'"'+ quote +'"'+",author:"+'"'+author+'"' +"};"+"\n"
    e.write(final)
    i=i+1
    f.close()
    e.close()