...

View Full Version : Formatting text to XML?



jbm715
04-30-2011, 12:48 AM
Ok,

So I am very new to PHP. My two partners and I have been working on a mashup that takes data from political websites and maps certain data to a google map. Because of the same origin policy we couldn't use Javascript to do the GET requests we needed; so we resorted to PHP. Using some PHP and cURL, we were able to get the text returned from the different API requests. The text is visually formatted in XML, but it is getting returned from cURL as plain text. I was wondering if there was a way to be able to return XML. Essentially, we are using a javascript function to call a php file that does the requests.

Please let me know if this doesn't make any sense. Thanks yall.

Fou-Lu
04-30-2011, 05:04 AM
Thats no problem. Use either the DOM or a simplexml to convert it into actual usable xml in php. I'm a fan of DOM myself, so that would be constructed as simple as:


$xml = DOMDocument::loadXML($yourCURLResponse);


And simple xml is as simple as:


$xml = new SimpleXML($yourCURLResponse);


Note that if this is simply to push back to JS, than you needn't at all push this into a XML type. Simply add a header:


header('Content-type: text/xml');

before any output, and print the results of the curl response. That will now be served as an XML document instead of a text/plain. Only use dom/simplexml if you plan on actually manipulating the xml in some fashion.

oesxyl
04-30-2011, 05:21 AM
Ok,

So I am very new to PHP. My two partners and I have been working on a mashup that takes data from political websites and maps certain data to a google map. Because of the same origin policy we couldn't use Javascript to do the GET requests we needed; so we resorted to PHP. Using some PHP and cURL, we were able to get the text returned from the different API requests. The text is visually formatted in XML, but it is getting returned from cURL as plain text. I was wondering if there was a way to be able to return XML. Essentially, we are using a javascript function to call a php file that does the requests.

Please let me know if this doesn't make any sense. Thanks yall.

http://opengovernmentdata.org/data/map/

best regards

jbm715
04-30-2011, 06:24 AM
Nice website but i'm not asking a question about goverment mashups. I guess I should've mentioned the project is academic. Any idea about my xml question?

oesxyl
04-30-2011, 07:08 AM
Nice website but i'm not asking a question about goverment mashups. I guess I should've mentioned the project is academic. Any idea about my xml question?
yes, kml is xml and you don't need to scrap pages for data because there are already started many projects for open gov data in few country. If you are from europe take a look to ckan.

http://ckan.net/

you also can find some tools which work with rdf/xml.
Shortest story the site is only a starting point to a not so new technology, :)
unfortunately there are only few projects which use php and i don't think this will help you too much.

best regards



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum