Here’s the code:
#!/usr/bin/python
import cgi, cgitb
import httplib2
import xmltodict, json
cgitb.enable()
query = cgi.FieldStorage()
q_value = query["q"].value
h = httplib2.Http()
resp, content = h.request("http://192.168.1.13:8080/solr/select?q=" + q_value, "GET")
p_xml = xmltodict.parse(content)
json_r = json.dumps(p_xml)
print "Content-type: application/json"
print
print json_r
I’m looking for comparable Perl modules to achieve the same effect, as I hear Perl is faster than Python doing these sort of things. The biggest ones here are obviously httplib2 and xmltodict, but the latter may just be because Python works well with dicts.
I’m very new to Perl and also new to programming in general, but Stack Overflow has been an incredible wealth of knowledge.
Doesn’t answer the question, but using Solr, you can add a
wt=jsonparameter and it will return json rather than XML…http://wiki.apache.org/solr/SolJSON