Objective-C DOM XML parser for iPhone - iphone

Hello guys I'm looking for a way on the iPhone to parse an XML document using DOM. I have been using SAX with NSXMLParser but now I really want a DOM tree (or anything that can quickly translate the XML document into an NSDictionary)
Thanks for any help

If you want to use libxml2 with an Objective-C front without SAX events, take a look at this useful set of wrapper functions.
You issue an XPath query to your XML document object and get back Foundation class objects: NSArray, NSString, and NSDictionary, e.g.:
NSArray *queriedBuckets = PerformXMLXPathQuery(responseData, #"//*[local-name()='Buckets']/*[local-name()='Bucket']");
These functions help merge the speed of libxml2 with the readability and usability of Objective-C code.

Unfortunately, NSXMLDocument (which does what you're asking) does not exist on the iPhone. You may have to roll your own parser using libxml2, or try something like TouchXML or KissXML.

I suggest looking at the Google Data API for Objective-C (iPhone) at http://code.google.com/p/gdata-objectivec-client/
In particular, look at these files which define the GDataXMLNode class:
http://gdata-objectivec-client.googlecode.com/svn/trunk/Source/XMLSupport/

Related

Converting JSON into Swift objects using Codable

I saw somewhere on StackOverflow there was a website that converted your JSON API into Struct and Codable protocols and for the life of me, I can't find it. I did not bookmark it, unfortunately. Any help would be appreciated in finding this site.
Try Quicktype. this web app allows you to convert JSON in Swift Type or any language such as Go, Dart, Java, C++, RUBY, etc.
https://app.quicktype.io/
just paste your json code in there and see the result:
jsoneditoronline

Can I add the CAArchive class to my iPhone project to serialize data? If so, how?

I have to use the CAArchiver class for the serialization of the data coming from the .bin file in my iPhone project (I need to use it in a C++ code snippet). How do I do this?
I have also researched the following link: http://msdn.microsoft.com/en-us/library/caz3zy5s(v=vs.80).aspx. This appears to be used in .NET technology.
What am I supposed to do?
CArchive (as per your link) is part of the Microsoft Foundation Class Library. It's very unlikely that you will find an implementation for them on the iOS platform.
If you need only to provide a kind of serialization, Jigneshs answer is the way to go. If you need to be compatible to other output from CArchive then chances are that you will have to implement this by yourself.
I do not know what you want:
but there is a class in iphone
NSData *data = [NSKeyedArchiver archivedDataWithRootObject:dictionary];
Where dictionary can be NSObject
NSObject *dictionary = [NSKeyedUnarchiver unarchiveObjectWithData:data];
Where data is a binary i.e. NSData
Using this, I think it will be helpful what you were looking for....

Parsing XML using libxml2 and Xpath in objective c

I want to parse an xml file using libxml2 and XPath
I have tried to look this up on the internet
but I can't find much about it.
Can anyone give me a sample code for parsing this xml:
<WebServiceResponse>
<status>OK</status>
<result>
<type>sample</type>
<name>Sample XML</name>
<location>
<lat>37.4217550</lat>
<lng>-122.0846330</lng>
</location>
</result>
<result>
<message>The secret message</message>
</result>
</WebServiceResponse>
just so I can work further
thanks in advance
this link may help you,
xml parsing iphone, objective C?
two automatic source creating: http://sudzc.com/
Download wsdl2objc and usage instructions here: http://code.google.com/p/wsdl2objc/wiki/UsageInstructions
Actually I am also looking for the code, please update once you find the answer.
You say you want to use libxml2 and XPath, but you don't say what you need XPath (presumably libxml2's implementation of the XPath 1.0 spec) to do. You ask for sample code to parse the XML, but you don't say what you want to do with the information in the XML, so it's hard answer your question.
If you really want to use libxml2, then you'll be writing most of your code in C because libxml2 is a C library. I recommend you use the libxml2 tutorial to get started. Based on that you should be able to try out some things. If you then have specific problems that you need to help with you can post more specific questions.
If you're not really committed to using libxml2 directly, and you prefer to write something more "native-like" in objective-C, then there are numerous frameworks for doing that including the built-in NSXMLParser class. There's no direct support for XPath or full-document XML processing built-in for iOS, but if what you want to do is parse the XML it should be relatively straightforward.
Good luck!

is it possible to make a Dynamic application with NSClassFromString()?

I want to use XML or JSON to told my app. I want to make a dynamic application that will change a feature by passing class from XML.
is it possible ?
if YES, could you please show me how to use NSClassFromString to interface with XML or JSON parser?
NSClassFromString() only returns a Class object. It's not possible to serialize a classes methods and unpack them in this way. You could define your own string format for classes but you can't add completely new methods at runtime (it's against the SDK rules).

Is there a native YAML library for iPhone?

I'm considering using YAML as part of my next iPhone application, but I haven't been able to find an Objective-C library to use.
The Wikipedia page for YAML mentions one, but the link is dead.
Is there an Objective-C library that can parse YAML into native collection objects (NSArray, NSDictionary, etc...)?
The Cocoa extensions for Syck are probably what you're looking for -- it's where the library that Shaggy Frog mentioned seems to be living these days.
You can try YAML.framework it's LibYAML based, it's fast and easy to use. Follows the same pattern as standard NSPropertyListSerialization.
You can use it for iOS (iPhone/iPad) development.
The YAMLKit framework is a thin wrapper around LibYAML. It does exactly what you want. For example:
[[YKParser alloc] init];
[p readString:#"- foo\n- bar\n- baz"];
id result = [p parse];
/* result is now an NSArray containing an NSArray with elements:
#"foo", #"bar", #"baz" */
[p release];
I recently wrote modern ObjC-YAML bindings, based on the standard NSCoder/NSKeyedArchiver interface: http://github.com/th-in-gs/YACYAML. I'm using them in my own projects, and intend to maintain them for at least as long as I continue to do so.
More here: http://www.blog.montgomerie.net/yacyaml
IF you are doing alot of c++ in your iPhone projects, then please have a look at yaml-cpp:
http://code.google.com/p/yaml-cpp/
has native iPhone support (via it's cmake build system)
has no dependencies beyond a good compiler and cmake
is very c++ friendly (thus, the name) with solid documentation (see the wiki/HowToParseADocument page)
I found this right from YAML's front page. But it looks like it might be out of date (c. 2004?), and the CVS link doesn't work for me.
I would bet that it's just a thin wrapper around an underlying C library like this or this... C code being "native" code that the Objective-C compiler will grok.
I found this question looking for YAML + objective C options. I ended up using this solution: https://github.com/icanzilb/JSONModel. Very cool, up to date and easy to use. Parses yaml directly into objective C models that you create inheriting the JSONModel class.