Jump to content

Working with XML & PHP.


sepoto

Recommended Posts

I have some data in a flat file. These are the fields:

nameaddressziplatlng

A row of data might look something like:

fishing hole #1, Catalina Island U.S., 90704, 33.3, 118.4

There are fifty rows of data. I am trying with PHP to encode this data into an XML file. The ultimate goal is that the data will be stored on the disk in XML format and when requested PHP will read the XML file and retrieve the data and put it into an array so I can encode the data in JSON and send it back off to JavaScript (AJAX). I'm very familiar with working with flat files and SQL however XML is a bit unfamiliar to me as of yet. How would this be accomplished? Good Evening W3Schools!

Link to comment
Share on other sites

you can use file() which will get you each line as array. you can then explode() the line as array. after that you can use dom to manupulate xml using dom. dom works same like you may used in js.http://php.net/dom techinicaly you may avoid the xml part .the array you get from file also can be encoded as json to pass it js,if it matches your situation.

Edited by birbal
Link to comment
Share on other sites

It looks very complicated! Could I see some code that would pertain to my data? I am seeing how to load and save the file that is easy. What looks much harder is how would be the best way to encode my data.

Edited by sepoto
Link to comment
Share on other sites

http://php.net/filehttp://php.net/explode it is as simple as i wrote the steps. you first check those function to see how they works . i am sure you will get the idea if youu look into those links. if you still have problem or any specific question come back,we will help you.
Link to comment
Share on other sites

A great suggestion. I have started to wonder myself why I should be bothering with the complexities of XML. Perhaps I will build a .CSV directly to JSON. XML would be more fun though.

Edited by sepoto
Link to comment
Share on other sites

  • 2 weeks later...
I have started to wonder myself why I should be bothering with the complexities of XML.
I have one reason for you - JavaScript. The DOM you use in PHP is the same as the one in JavaScript... well... the spec is the same at least. The point is that if you master DOM in one environment, you can reuse your skills in the other environment. You can't really do that with CSV. You can sort of do it with JSON, except that you'd still end up using DOM with JavaScript, as it's tightly integrated with browsers' JS engines.
  • Like 1
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...