MantleXMLExtension 1.2.2

MantleXMLExtension 1.2.2

LangLanguage Obj-CObjective C
License Unknown
ReleasedLast Release Jun 2018

Maintained by soranoba.

  • By
  • soranoba


Build Status Carthage compatible Version License Platform

MantleXMLExtension support mutual conversion between Model object and XML with Mantle.


Mantle support the Json, but doesn't support XML.

This application is an extension for handling xml with Mantle.

  • Support these
    • Attributes
    • Child nodes, Nested child nodes, Array of child nodes
    • Customizable order of child nodes
    • Customizable XML declaration
    • Customizable transformer

What is Mantle ?

Model framework for Cocoa and Cocoa Touch



To install it, simply add the following line to your Podfile:

pod 'MantleXMLExtension'


To install it, simply add the following line to your Cartfile:

github "soranoba/MantleXMLExtension"

How to use functions of MantleXMLExtension

Conversion between Model object and XML

// XML to Model
id<MTLModel> model = [MXEXmlAdapter modelOfClass:model.class

// Model to XML
NSData* data = [MXEXmlAdapter xmlDataFromModel:model error:&error];

Model definition

Just add some to MTLModel for MXEXmlAdapter.

#pragma mark - MXEXmlSerializing

+ (NSDictionary<NSString*, id>* _Nonnull)xmlKeyPathsByPropertyKey
    return @{ @"status" : MXEXmlAttribute(@"", @"status"),
              @"userCount" : @"summary.count",
              @"users" : MXEXmlArray(@"", MXEXmlChildNode(@"user")) };

+ (NSString* _Nonnull)xmlRootElementName
    return @"response";

Path type

MXEXmlAdapter support 5 types of paths.


For example:


If you get value, please use this. Value doesn't support MXEXmlSerializing object.


For example:

  <child key="value" />
MXEXmlAttribute(@"parent.child", @"key")

If you get value of specified attribute, please use this.


For example:


If you get nested MXEXmlSerializing object, please use this. This path only support MXEXmlSerializing object.


For example:

MXEXmlArray(@"parent.children", MXEXmlChildNode(@"child"))

If you get array of value, please use this. This path can be used in combination with other path.

If you use this, you MUST use MXEXmlAdapter # xmlNodeArrayTransformerWithModelClass:.

+ (NSValueTransformer* _Nonnull)childrenXmlTransformer
    return [MXEXmlAdapter xmlNodeArrayTransformerWithModelClass:ChildModel.class];

Multiple elements of XML

For example:

  <element_b title="...." />
@[@"parent.element_a", MXEXmlAttribute(@"parent.element_b", @"title")]

It is used when you want to transfer multiple elements of XML to another model. Please notice that root element of XML does not change.


You can use these transformer for MXEXmlSerializing object.

  • MXEXmlAdapter # xmlNodeArrayTransformerWithModelClass:
  • MXEXmlAdapter # xmlNodeTransformerWithModelClass:
  • MXEXmlAdapter # mappingDictionaryTransformerWithKeyPath:valuePath:

You can use these transformer for primitive type.

  • MXEXmlAdapter # numberTransformer
  • MXEXmlAdapter # boolTransformer

Other information

Please refer to documentation, unit tests and Mantle.


Pull request is welcome =D


MIT License