Is there a standard way to load, read and parse an XML file from Cocoa?
I followed the solution in this question but I can’t quite get it, I am getting all confused. I’m a C programmer and obj-c is not my strong point. The idea is to parse the XML file and load the data into several objects on the GUI.
Thank you for the help.
EDIT
This is an example of the XML I need to parse. I need a full example of how to do this since all the bit and pieces of examples that I found are taking me nowhere. Thank you, I appreciate the help.
<Project Name="Accountant">
<Name>
Some Name
</Name>
<Year>
2011
</Year>
<ApplicationStatus>
In Progress
</ApplicationStatus>
<OutputDir>
/SomePath/To/a/FileName
</OutputDir>
</Project>
The
NSXMLParserparse some XML Data in cooperation with its delegate. You first alloc/init the parser, giving it either directlyNSDataobject (containing your XML Data), or a URL where it can retrieve the XML Data to parse.Then you give the parser a reference to the delegate by setting its
delegateproperty, and finally ask the parser to parse the data.This is described in Event-Driven XML Programming Guide.
To be short,
NSXMLParseris object that do parse the data, but you won’t obtain any elements or attributes from it.Instead, the parser tells its delegate when it finds something, and the delegate can then handle the element or attribute. That also means you don’t have to wait for the parser to finish its job, you just tell it to begin parsing.
So in this schema, the big job is to implement
NSXMLParser‘s delegate methods depending on what you want to do with the XML.If you need detailed informations about each classes you can also visit :
NSXMLParser Class Reference.
NSXMLParserDelegate Protocol Reference.