-2

i want to store my data (which i am gathering through my app) to xml and then send it to my webspace. How should i do it??

vikingosegundo
  • 52,040
  • 14
  • 137
  • 178
Ashutosh
  • 5,614
  • 13
  • 52
  • 84
  • There may be some info in http://stackoverflow.com/questions/406811/iphone-development-xmlparser-vs-libxml2-vs-touchxml – Preet Sangha Sep 17 '10 at 00:02
  • Or in http://stackoverflow.com/questions/857668/generate-xml – Preet Sangha Sep 17 '10 at 00:03
  • Please clarify your question as it is too vague. Are you asking how to structure data in an XML form? How to dynamically generate an XML document in-memory? How to do an HTTP request using POST to send data to a Web server? – Shaggy Frog Sep 17 '10 at 00:26
  • You have mentioned all the three question i wanted to ask but the answer below cleared my third part which is sending the data to web. – Ashutosh Sep 17 '10 at 00:50
  • Just need the answer of above two :1) asking how to structure data in an XML form? 2) How to structure data in an XML form? – Ashutosh Sep 17 '10 at 00:58
  • My answer was helpful? Don't hesitate to vote up! – vikingosegundo Sep 17 '10 at 01:03

1 Answers1

1

Your question contains several tasks.

Here is a solution for the upload part:

On sever-side you need to have a file-upload.

On iOS-side I suggest the usage of ASIHttpRequest

ASIFormDataRequest *request = [ASIFormDataRequest requestWithURL:url];
[request setFile:@"path/to/ur/xml" forKey:@"file"];

edit

Creating a (simple) XML-file should be quite easy, as it can be done just with String-operations.

  1. fill a (mutable) Array with the objects you want to write to the xml
    • let's say, you have a collected address book data. you filled the array with Contacts objects
    • each contact has n addresses, that are stored in an array, a name,...
  2. take the last object in the array
  3. write <contact name="%@"> to a string, with passing in the contacts name
  4. loop over the addresses and write <address kind="%@"> with specifying kind as "work", "private", "other"
  5. do similair with the address data (street, city,...)
  6. when done with a adress write </address>
  7. when done with a contact write </contact>
  8. remove last contact from array
  9. if the array isnt empty, start again with 2.
  10. wenn done with all data in the array, add <adressbook>in the beginning of the string and </addressbook> at the end.
vikingosegundo
  • 52,040
  • 14
  • 137
  • 178
  • It looks good man please have a look at my comments above if you can help – Ashutosh Sep 17 '10 at 01:07
  • If it looks good, it should worth an upvote (the top arrow). This doesnt mean you have to accept the answer. – vikingosegundo Sep 17 '10 at 01:49
  • creating your own XML using strings is discouraged, rather do as above using an XML writer of some sort. and make sure you use some form of UTF encoding for the resulting XML string, so that international characters are supported in the names. – ThomasRS Feb 03 '11 at 14:58