SDMParser

The SDMParser library provides APIs to convert OData XML payloads to native Objective-C objects and structures (arrays, dictionaries).

List of Features

SDMParser Public APIs

SDMODataServiceDocument* sdmParseODataServiceDocumentXML(NSData* const content_in)
SDMODataSchema* sdmParseODataSchemaXML(NSData* const content_in, SDMODataServiceDocument* const serviceDocument)
NSMutableArray* sdmParseODataEntriesXML(NSData* const content_in, const SDMODataEntitySchema* const entitySchema, const SDMODataServiceDocument* const serviceDocument)
SDMODataError* sdmParseODataErrorXML(NSData* const content_in)
NSMutableArray* sdmParseFunctionImportResult(NSData* const content_in, const SDMODataFunctionImport* const functionImport)
SDMOpenSearchDescription* sdmParseOpenSearchDescriptionXML(NSData* const content_in)
SDMODataEntryXML* sdmBuildODataEntryXML (const SDMODataEntry *const entry, const enum TEN_ENTRY_OPERATIONS operation, const SDMODataServiceDocument *const serviceDocument, const BOOL serializeInlinedEntries)
SDMODataFeedXML* sdmBuildODataFeedXML (NSArray *const entries, const enum TEN_ENTRY_OPERATIONS operation, const SDMODataServiceDocument *const serviceDocument, const BOOL serializeInlinedEntries)

Technical Details

The listed C-style parser APIs are provided for convenience. You can choose to instantiate the dedicated parser classes. As a reference, the following code excerpt shows how the C-style APIs wrap the parser calls:
/**
 * Parses the service document XML and converts it to an Obj-C service document object.
 */
SDMODataServiceDocument* sdmParseODataServiceDocumentXML(NSData* const content_in) {
	SDMODataServiceDocumentParser* svcDocParser = [[[SDMODataServiceDocumentParser alloc] init] autorelease];
	[svcDocParser parse: content_in];
	
	return svcDocParser.serviceDocument;
}


/**
 *	Parses and matches the schema with the service document and its collections. The function returns the same
 *  schema pointer as it can already be found in the serviceDocument.
 */
SDMODataSchema* sdmParseODataSchemaXML(NSData* const content_in, SDMODataServiceDocument* const serviceDocument) {
	if (!serviceDocument)
		//@throw [[[SDMParserException alloc] initWithName: @"NoServiceDocument" reason: @"No service document was provided" userInfo: nil] autorelease];
		@throw [[[SDMParserException alloc] initWithError: ParserNoServiceDocument detailedError: @"No service document was provided"] autorelease];
		
	SDMODataMetaDocumentParser* metaDocParser = [[[SDMODataMetaDocumentParser alloc] initWithServiceDocument: serviceDocument] autorelease];
	[metaDocParser parse: content_in];
	
	return serviceDocument.schema;
}


/**
 * Parses a feed or entry XML and returns an array of parsed entry/entries. 
 * Any "inlined"entries or feed(s) will be parsed when service document is passed to the function. If "inlined" feed(s) or entries 
 * should not be returned pass nil in the service document parameter.
 */
NSMutableArray* sdmParseODataEntriesXML(NSData* const content_in, const SDMODataEntitySchema* const entitySchema, const SDMODataServiceDocument* const serviceDocument) {
	if (!entitySchema)
		//@throw [[[SDMParserException alloc] initWithName: @"NoEntitySchema" reason: @"No entity schema was provided" userInfo: nil] autorelease];
		@throw [[[SDMParserException alloc] initWithError: ParserNoEntitySchema detailedError: @"No entity schema was provided"] autorelease];
	
	SDMODataDataParser* dataParser = [[[SDMODataDataParser alloc] initWithEntitySchema: entitySchema andServiceDocument: serviceDocument] autorelease];
	[dataParser parse: content_in];
	
	return dataParser.entries;	
}


/**
 * Parses an OData error payload XML
 * @see SDMODataError
 */
SDMODataError* sdmParseODataErrorXML(NSData* const content_in) {
	SDMODataErrorXMLParser* errorParser = [[[SDMODataErrorXMLParser alloc] init] autorelease];
	[errorParser parse: content_in];
	
	return errorParser.odataError;
}

/**
 * Parses the result payload XML of a function import.
 * @returns Returns an array of entries.
 * @remark Even if the result is not a feed or entry XML, the parser creates an entity schema out of the return type definition, so
 * application developers can access the returned data in a uniform way. The supported return types are:
 * - none
 * - EDMSimpleType		(for example: ReturnType="Edm.Int32"), the generated "entity" schema will be "element" with type Edm.Int32
 * - ComplexType		(for example: ReturnType="NetflixCatalog.Model.BoxArt")
 * - Collection of an EDMSimpleType (for example: ReturnType="Collection(Edm.String)")
 * - Collection of a ComplexType    (for example: ReturnType="Collection(NetflixCatalog.Model.BoxArt)")    
 * - Entry	(for example ReturnType="NetflixCatalog.Model.Title" EntitySet="Titles")
 * - Feed   (for example ReturnType="Collection(NetflixCatalog.Model.Title)" EntitySet="Titles")
 */
NSMutableArray* sdmParseFunctionImportResult(NSData* const content_in, const SDMODataFunctionImport* const functionImport) {
	SDMFunctionImportResultParser* fiParser = [[[SDMFunctionImportResultParser alloc] initWithFunctionImport: functionImport] autorelease];
	[fiParser parse: content_in];
	
	return fiParser.entries;
}


/**
 * Parses an XML that contains Open Search Description
 * The parsed data is returned in an SDMOpenSearchDescription typed object.
 */
SDMOpenSearchDescription* sdmParseOpenSearchDescriptionXML(NSData* const content_in) {
	SDMOpenSearchDescriptionXMLParser* osdParser = [[[SDMOpenSearchDescriptionXMLParser alloc] init] autorelease];
	[osdParser parse: content_in];
	
	return osdParser.openSearchDescription;
}

The SDMParser library communicates error conditions to the client via the dedicated SDMParserException exception class. Whenever a mandatory attribute is missing, the parser throws an exception.

The caller is responsible for error handling; this includes fetching the details included in the exception, logging information meant for debugging purposes, displaying a localized alert message, and providing a resolution or stopping the application flow.

The Service Document Component

Root object. Contains the schema object, the function imports, the document language, base URL (if any) and the server type.

SDMOdataServiceDocument

-(enum TEN_SERVER_TYPES)getServerType
-(NSString*)getDocumentLanguage
-(NSString*)getBaseUrl
-(SDMODataSchema*)getSchema
-(NSMutableDictionary*)getFunctionImports

The Schema Component

The schema contains workspaces and helper methods to work with collections via workspaces.

SDMODataSchema

-(NSArray*) getWorkspacesBySemantic:(const enum TEN_WORKSPACE_SEMANTICS)workspaceSemantic
-(SDMODataCollection*) getCollectionByName:(NSString* const)collectionName
-(SDMODataCollection*) getCollectionByName:(NSString* const)collectionName workspaceOfCollection:(SDMODataWorkspace**)workspaceOfCollection

The Workspace Component

A workspace can contain 0 up to n collections. Each workspace can have a title and a semantic value.

SDMODataWorkspace

-(enum TEN_WORKSPACE_SEMANTICS) getSemantic
-(NSString*) getTitle
-(NSMutableDictionary*) getCollections

The Collection Component

Represents one parsed collection.

SDMODataCollection

-(id) initWithName:(NSString* const)newName
-(BOOL) isCreatable
-(BOOL) isUpdatable
-(BOOL) isDeletable
-(BOOL) isTopLevel
-(BOOL) doesRequireFilter
-(BOOL) hasMedia
-(SDMODataLink*) getSubscriptionLink
-(int) getContentVersion
-(enum TEN_COLLECTION_SEMANTICS) getSemantic
-(uint8_t) getFlags
-(NSString*) getName
-(NSString*) getTitle
-(NSString*) getMemberTitle
-(NSMutableArray*) getIcons
-(NSMutableArray*) getLinks
-(int) getDisplayOrder
-(SDMODataEntitySchema*) getEntitySchema
-(SDMOpenSearchDescription*) getOpenSearchDescription

The Entity Schema Component

An instance of the EntitySchema class stores the root of the structure of the given collection with constraints. The entity schema class also provides helper functions to order the visible fields of a collection and the navigation map that maps navigation names to collection names.

SDMODataEntitySchema

-(id) init
-(int) getContentVersion
-(uint16_t) getFlags
-(SDMODataPropertyInfo*) getRoot
-(NSMutableDictionary*) getNavigationMap
-(NSArray* const) getVisibleInListPathsInOrder
-(NSArray* const) getVisibleInDetailPathsInOrder

The Property Info Component

A property info instance stores the name, type and all constraints of a property, but does not store property values.

SDMODataPropertyInfo

-(id) initWithName:(NSString* const)propName andPropEdmType:(const enum TEN_EDM_TYPES)propEdmType
-(BOOL) isNullable
-(BOOL) isKey
-(BOOL) isCreatable
-(BOOL) isUpdatable
-(BOOL) isFilterable
-(BOOL) isVisibleInList
-(BOOL) isVisibleInDetail
-(BOOL) isSearchable
-(BOOL) isServerGenerated
-(void) addChildPropertyInfo:(const SDMODataPropertyInfo* const)child
-(SDMODataPropertyInfo* const) getPropertyInfoByPath:(NSString* const)path
-(NSString*) getName
-(enum TEN_EDM_TYPES) getType
-(uint16_t) getFlags
-(int) getMaxLength
-(enum TEN_PROPERTY_SEMANTICS) getSemantic
-(uint32_t) getSemanticTypes
-(NSString*) getLabel
-(NSString*) getDescription
-(int32_t) getListDisplayOrder
-(int32_t) getDetailDisplayOrder
-(uint8_t) getScale
-(uint8_t) getPrecision
-(NSMutableDictionary*) getChildren

The Function Import Component

Function imports can be used to execute back-end functionalities that are not related to collections, or functionalities other than the possible create, update, delete and read operations for collections. An instance of SMDODataFunctionImport stores all the information and has all the methods necessary to execute such a back-end functionality.

SDMODataFunctionImport

-(id) initWithName:(NSString* const)newName
-(NSString*) getName
-(NSString*) getHttpMethod
-(NSMutableDictionary*) getParameters
-(SDMODataEntitySchema*) getReturnTypeSchema
-(uint8_t) getFlags
-(NSString*) getActionFor
-(NSMutableDictionary*) getWritableParameters
-(NSString*) generateFunctionImportUrl:(NSString* const)baseUrl parameters:(NSDictionary* const)parameters

The Link Component

The OData SDK provides four types of link classes depending on the usecase:
  • SDMODataLink
  • SDMODataRelatedLink (this class inherits all the methods mentioned at SDMODataLink)
  • SDMODataMediaResourceLink (this class inherits all the methods mentioned at SDMODataLink)
  • SDMODataActionLink(contains the optional parameters of the action and the helper method to assemble the final URL that is required to execute the action)
SDMODataLink

-(NSString*) getHRef
-(NSString*) getRel
-(NSString*) getType
-(NSString*) getTitle
-(enum TEN_LINK_SEMANTICS) getSemantic


DMODataRelatedLink

-(NSString*) getTargetCollection


SDMODataMediaResourceLink

-(NSString*) getConcurrencyToken


SDMODataActionLink

-(NSString*) getHttpMethod;
-(NSMutableDictionary*) getDefaultParameterValues;
-(NSDictionary*) getParameters;
-(NSString*) createActionLinkURL:(NSDictionary*)parameters;


The Open Search Description Component

An SDMOpenSearchDescription instance stores the parsed short name, description and the URL templates for searching data.

SDMOpenSearchDescription

-(NSString*) getShortName
-(NSString*) getDescription
-(NSMutableArray*) getUrlTemplates

SDMOpenSearchDescriptionURLTemplate

-(NSString*) getUrlTemplate
-(NSString*) getUrlType
-(NSString*) createUrlWithParameters:(NSDictionary*)parameters

The Property Value Objects Component

An instance of the property value object stores a value and its metadata (property info instance). SDMODataPropertyValueObject is the base property value class that provides basic validation and value accessors. Derived classes of this class redefine certain methods (for example, validation checks) of the base class and provide methods allowing the library user to access data as typed data instead of string data.

SDMODataPropertyValueObject (base class)

-(NSString* const) getHTMLEncodedValue
-(NSString* const) getDefaultValue
-(BOOL) isValid
-(NSString*) getValue
-(void) setValue:(NSString*) value
-(enum TEN_EDM_TYPES) getEdmType
-(const SDMODataPropertyInfo* const) getPropertyInfo
-(BOOL) isValidationDisabled
-(void) setValidationDisabled:(BOOL)validationDisabled