Latest1.2.1
Homepagehttps://github.com/DZamataev/RKXMLDictionarySerialization
LicenseMIT
Platformsios 5.1.1, requires ARC
Authors

another way of ‘RestKit’ XML serialization using nicklockwood`s XMLDictionary

The XMLDictionary allows the user to tweak XML parsing settings on the go.
With RKXMLDictionarySerialization use [RKXMLDictionarySerialization sharedParser] to do it.

NOTE the way you describe RestKit mapping is a bit special according to the XML node inner text.
The inner text property of XML node is named ‘__text’.
Thats made in order to make XML parsing uniquely, so that no "attribute name vs inner node name" collision can happen.

The mapping for

<root>
  <node>
    barbarbar
  </node>
</root>

becomes

node.__text

Installation

Cocoapods

Podfile

pod 'RKXMLDictionarySerialization'

Usage

Once installed, register the serialization in your model class (or wherever you handle RestKit setup):

#import "RKXMLDictionarySerialization.h"

[RKMIMETypeSerialization registerClass:[RKXMLDictionarySerialization class] forMIMEType:RKMIMETypeTextXML];
[RKMIMETypeSerialization registerClass:[RKXMLDictionarySerialization class] forMIMEType:RKMIMETypeXML];

Note that you may register the class for more than one MIME Type or use an NSRegularExpression that matches the MIME Type that you wish to register. For more details, review the API Documentation.

Main idea

The most useful feature and the reason this solution exists is that RKXMLReaderSerialization (https://github.com/RestKit/RKXMLReaderSerialization)
got problems with collision between xml node attribute names and inner node names.

Such XML

<root>
  <node body='regular'>
    <body>
      foobar
    </body>
  </node>
</root>

is nearly impossible to map correctly with RKXMLReaderSerialization and easily handled with RKXMLDictionarySerialization

And after parsing with XMLReader or without tweaking XMLDictionary settings it just becomes something strange:

root =     {
        node =         {
            body =             (
                regular,
                                {
                    "__text" = foobar;
                }
            );
        };
    };

But with XMLDictionarySerialization you`ve got XMLDictionary configured to prefix attribute names by default and it parses it correctly

root =     {
        node =         {
            "_body" = regular;
            body =             {
                "__text" = foobar;
            };
        };
    };

so the object mapping described via RestKit should pay attention to the attribute names because prefixing is enabled by default.


follow button

endorse

Latest podspec

{
    "name": "RKXMLDictionarySerialization",
    "version": "1.2.1",
    "summary": "A RestKit serialization format implementation for XML using XMLDictionary.",
    "homepage": "https://github.com/DZamataev/RKXMLDictionarySerialization",
    "license": {
        "type": "MIT",
        "file": "LICENSE"
    },
    "authors": {
        "Denis Zamataev": "[email protected]"
    },
    "source": {
        "git": "https://github.com/DZamataev/RKXMLDictionarySerialization.git",
        "tag": "1.2.1"
    },
    "platforms": {
        "ios": "5.1.1"
    },
    "requires_arc": true,
    "default_subspecs": "Core",
    "subspecs": [
        {
            "name": "Core",
            "requires_arc": true,
            "source_files": "Core/*",
            "dependencies": {
                "RKXMLDictionarySerialization/Core-no-arc": [],
                "RestKit": [],
                "XMLDictionary": [
                    ">= 1.4"
                ]
            }
        },
        {
            "name": "Core-no-arc",
            "requires_arc": false,
            "source_files": "Core-no-arc/*"
        },
        {
            "name": "Demo",
            "requires_arc": true,
            "source_files": "Demo/RKXMLDictionarySerializationDemo/Source/*",
            "resources": "Demo/RKXMLDictionarySerializationDemo/Resources/*",
            "preserve_paths": [
                "Demo/RKXMLDictionarySerializationDemo.xcodeproj",
                "Demo/Podfile"
            ],
            "dependencies": {
                "RKXMLDictionarySerialization/Core": []
            }
        }
    ]
}

Pin It on Pinterest

Share This