DADynamicWhereXmlGenerator

Overview

DADynamicWhereXmlGenerator class is used for transformation NSPredicate expression into Dynamic Where xml which could be used as the filter during fetching data from the server side.

In the world of Cocoa, to determine the various requests are widely used NSPredicate. This is a very handy feature. For example, if we have an array filled with objects that have a property Name, we can easily filter them by given name in following way:

 
NSPredicate *lFilter = [NSPredicate predicateWithFormat:@"name == %@", name];
NSArray* result = [collection filteredArrayUsingPredicate:lFilter];

Inside the Data Abstract we can use NSPredicate expressions for so called client-side filtering rows of the DADataTable.

 
// Client-side filtering data
NSPredicate * lFilter = [NSPredicate predicateWithFormat:@"WorkerPosition contains[cd] %@", @"Representative"]; 
self.rows = [[workersTable rows] filteredArrayUsingPredicate:lFilter];
[tableView reloadData];

But at the same time we can apply server-side filtering using the same NSPredicate expression. To do this we just need to transform given NSPredicate expression to the proper Dynamic Where xml which can be used in requesting data from the server side.

the DADynamicWhereXmlGenerator class provides such transformation for us.

 
// Server-side filtering data
NSPredicate * lFilter = [NSPredicate predicateWithFormat:@"WorkerPosition contains[cd] %@", @"Representative"]; 
NSString *dynWhereXml = [DADynamicWhereXmlGenerator generateXmlFromPredicate:lFilter autoIndent:YES];
DADynamicWhereClause *clause = [DADynamicWhereClause dynamicWhereClauseWithXmlString:dynWhereXml];
request = [rda beginGetDataTable:@"Workers" 
                          select:[self fieldsToSelect] 
                           where:clause
                           withBlock:^(DADataTable *table){
                              self.workersTable = table;
                              self.rows = [workersTable rows];
                              [tableView reloadData];
                           }];

in the code above [DADynamicWhereXmlGenerator generateXmlFromPredicate:lFilter] will produce following Dynamic Where xml:


<?xml version="1.0" encoding="utf-16"?>
<query xmlns="http://www.remobjects.com/schemas/dataabstract/queries/5.0" version="5.0">
  <where>
    <binaryoperation operator="Like">
      <field>WorkerPosition</field>
      <constant type="String" null="0">%Representative%</constant>
    </binaryoperation>
  </where>
</query>

Location

 

decodeXmlStringValue:    (declared in DABaseXmlSerializer)

+ (NSString *) decodeXmlStringValue:(NSString *)value

Parameters:

  • value:

encodeXmlStringValue:    (declared in DABaseXmlSerializer)

+ (NSString *) encodeXmlStringValue:(NSString *)value

Parameters:

  • value:

generateXmlFromPredicate:

Class method generates XML string for given NSPredicate

+ (NSString *) generateXmlFromPredicate:(NSPredicate *)predicate

Parameters:

  • predicate: NSPredicate instance which should be translated into Dynamic Where XML

generateXmlFromPredicate:autoIndent:

Class method generates XML string for given NSPredicate. Allows to specify autoIndent flag. If autoIndent is YES then method returns formatted XML string with proper indentation.

+ (NSString *) generateXmlFromPredicate:(NSPredicate *)predicate autoIndent:(BOOL)autoIndent

Parameters:

  • predicate: NSPredicate instance which should be translated into Dynamic Where XML
  • autoIndent: Boolean flag that specify apply auto-indentation for result XML string. Default value is NO

setAutoIndent:    (declared in DABaseXmlSerializer)

- (void) setAutoIndent:(BOOL)value

Parameters:

  • value:

xmlString    (declared in DABaseXmlSerializer)

- (NSString *) xmlString

 

decodeXmlStringValue:    (declared in DABaseXmlSerializer)

+ (NSString *) decodeXmlStringValue:(NSString *)value

Parameters:

  • value:

encodeXmlStringValue:    (declared in DABaseXmlSerializer)

+ (NSString *) encodeXmlStringValue:(NSString *)value

Parameters:

  • value:

generateXmlFromPredicate:

Class method generates XML string for given NSPredicate

+ (NSString *) generateXmlFromPredicate:(NSPredicate *)predicate

Parameters:

  • predicate: NSPredicate instance which should be translated into Dynamic Where XML

generateXmlFromPredicate:autoIndent:

Class method generates XML string for given NSPredicate. Allows to specify autoIndent flag. If autoIndent is YES then method returns formatted XML string with proper indentation.

+ (NSString *) generateXmlFromPredicate:(NSPredicate *)predicate autoIndent:(BOOL)autoIndent

Parameters:

  • predicate: NSPredicate instance which should be translated into Dynamic Where XML
  • autoIndent: Boolean flag that specify apply auto-indentation for result XML string. Default value is NO

 

setAutoIndent:    (declared in DABaseXmlSerializer)

- (void) setAutoIndent:(BOOL)value

Parameters:

  • value:

xmlString    (declared in DABaseXmlSerializer)

- (NSString *) xmlString

See Also