Skip to content
an iPhone XML to NSDictionary converter
Objective-C C
Pull request Compare This branch is 12 commits ahead, 1 commit behind bcaccinolo:master.
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.
LICENCE
README
XMLReader.h
XMLReader.m

README

The key ideas:

  1 XML elements map to key names in the dictionary
  2 Each element corresponds to a child dictionary
  3 Attribute key-value pairs are added to the element’s child dictionary
  4 Strings from text nodes are assigned to the child dictionary’s “text” key
  5 If an element name is encountered multiple times, the value of the element is set to an array of children dictionaries

----Additions to NSDictionary----
The retrieveForPath: method allows easy selection of items in a nested NSDictionary structure, using a string in
the familar dot syntax. Items in NSArrays inside the hierarchy can also be moved through using object indexes, or
by using "last" to get the last object in the array.

For example, the following nested NSDictionary:
NSDictionary *exampleDict =
{
  results = {
      example1 = {
          hash = 4H5keM;
          string1 = "foo";
          string2 = "bar";
          userDetails = {
              { firstName = "John";  lastName = "Smith"; userName = "JSmith"; userID = 12345; },
              { firstName = "Jane";  lastName = "Doe"; userName = "JDoe"; userID = 54321; },
          };
      };
  };
  statusCode = OK;
}

The firstName of Jane's record can be quickly accessed by using:
[exampleDict retrieveForPath:@"results.example1.userDetails.last.firstName"];

The firstName of John's record can be quickly accessed by using:
[exampleDict retrieveForPath:@"results.example1.userDetails.0.firstName"];

Unfortunately NSArrays in the heirarchy seriously obfuscates the NSDictionary structure, and you'll have to know the index of the item you want when NSArrays appears.
Something went wrong with that request. Please try again.