For an iPhone application I need to request data from an online database. I choice to use for an restful web service. Main reason because it will connect to an JAVA server.
I did find a useful wrapper that helps me to get the data but now I need a good workaround to play with the data. The output is XML. If it is better to use JSON or something else please let me know.
In this situation I search in the online database and I only get names back. Like this:
Name 1
Name 2
Name 3
The situation is now pretty simple. I know you can choice for NSXMLParser but I little bit hate the way the parser works: didStartElement, didEndElement and foundCharacters.
I was wondering if there is a better way to do it. Maybe you have a link to a website with useful information.
There are several. If these are fairly small XML documents (as I expect), then you should look at TouchXML and TouchJSON. If you also want a more full-featured version (including writing XML documents), look at KissXML.
Related
I do not have control of how this data is stored (I know as normalized data would be better for sql), because it is saved via the WordPress GravityForms plugin. The plugin uses a serialized array to define the question id (field_id), question label (label). My goal is to extract these three values in the following format:
field_id label
1 1. I know my organization’s mission (what it is trying to accomplish).
2 2. I know my organization’s vision (where it is trying to go in the future).
Here is the serialized array.
Can anyone please provide a specific example as to how to parse these values out with sql?
A specific example, no. This kind of stuff is complex. If your are working with straight json-formatted data, here are several options, none of which are simple.
You can build your own parser. Yuck.
You can upgrade everything you have to just-released SQL 2016, and hope that the built-in json tools do what you need (I've heard iffy things about them, but don't know what their final form is like. Too, updating all your database servers right now, oh sure.)
Phil Factor over on SimpleTalk built a json T-SQL parser (https://www.simple-talk.com/sql/t-sql-programming/consuming-json-strings-in-sql-server/). It looks horrible and may run poorly, but it would do the needful.
Buried in the comments of that article are links to a CLR tool that John Galt built (at https://github.com/jgcoding/J-SQL). I have used this successfully, though I haven't done anything too complex. (If you're json is relatively simple, this could do the trick.)
There are other json parsers for SQL out there, some free, some for sale. The key thing would be to not try and write your own, but rather find and use someone else's solution that addresses your requirements.
I'm currently trying to create a parser to populate my core data database. I have tried using NSXMLParser, where I realized that would be kinda difficult. Because I cant handle the xml document well enough.
Then I searched and found that I could use multiple delegates for handling complex documents.
I tried to find some tutorials/guides/examples for this. But I only examples with simple XML files.
I found this similar to mine. NSXMLParser with multiple delegates
But the guy doesn't get any answers.
Maybe some people here have some examples?
Thanks in advance.
The XML structure of the guy you mentioned is quite easy to parse, he most probably is doing it wrong in the code he didn't show. You do not need to use multiple delegates to parse an XML file. You've already said you've got some sort of data model in your app. You need to create an NSXMLParser subclass and temporary data model objects. Then listen which tag is currently being parsed and store the data in your temporary objects, saving them into the NSManagedObjectContext. Really its that simple. If that doesn't makes it clear, put your xml document in the question and I'll try to explain this with as much code as possible.
I'm building an IOS application, and would like to offer the user the ability to use macros for different aspects of the system.
For example, I might have a simple macro this this:
{include name="some name" pre="some it of htmk" post="some other bit of html"}
That would include the contents of the item named "some name" in the body of the document the user is working on.
or I might have something more complex like this:
{notesForTag name={ListAllTags pre="some bit of html" post="some other bit of html"} pre="..." post="..."}
Which would list all the documents in the system grouped by tag.. the ability to add on data (like html) at the beginning and the end of each tag returned would allow the user, for example, to format the response as a table, or use particular styling, etc.
Conceptually, I know how I want this to work, but I'm wondering if there are any macro construction and processing best practices out there that would help me on my way. Anything geared towards Objective C / IOS would be most helpful.
Edit: To add some clarity here, what I'm looking to discover is an efficient and accurate way to parse something like this. Having parsed things, I think the rest will be fairly straightforward.
Thank you.
NSScanner would probably work well for parsing something like this, perhaps with a recursive function to allow nested macros like the second one. You may also want to consider using XML to represent your macros, which would allow you to use NSXMLParser to parse it, so you only have to worry about the content and not the structure.
I have my application talking to a server. What I need to do is pull information from the Core Data persistent store and parse it to XML, then send it to the server. The server will respond in XML and I will need to parse this back to Core Data.
What is the best way to do this? I'm aware of NSXMLParser but unfortunately I haven't found any good tutorials on how to use it for my application.
Edit: There are so many better things than NSXMLParser now. Check SO for more answers.
As far as writing your data out as XML goes, you'll probably find this Stackoverflow Question helpful.
Sending the data back and forth can be done using an NSURLConnection with a custom delegate.
Retrieving the data from the XML can be done using NSXMLParser, like you said.
This may sound like a noobish question (in fact, it is), but I can't figure out what I should use to save between sessions:
NSStrings
NStextStorages
I've found some alternatives, but I don't know which is best for the case and why:
Core Data (or has it nothing to do?)
SQL
Edit: I have a simple interface that adds "posts" to a database (that doesn't exist yet, hence my question). Each "post" has a "title" one or two "authors" and a "body". While the "title" and the "authors" are plain strings (NSStrings), the "body" is rich text (NSTextStorage). But I don't want to save files, I want to generate a database that I could then use to format automatically and generate a PDF file (for me to print). I've been reading Core Data and it looks like the way to go, I'm just not sure how I could then convert my data and format it into a PDF.
Core Data would probably be great for what you're doing, although anything you do with Core Data you can probably do with SQL if you already know it.
Read the Core Data guides. Basically you lay out your schema and then can add or remove managed objects from the managed object context. Core Data is nice because it can do a lot of validation for free, and is good performance.
I was in a similar situation not too long ago.. and although im developing for iPhone, i belive the principle would be the same.. i found core data to be very useful, once i got to grips with it it proved to be quite useful..
if your saving a lot of information/data, than core data may be the way to go..
hope this helps :)