if ( !super::validate(xmlLiteParser, xmlPath, keyPos, generateErrors) ) return false;
if ( value() <-2){
xmlLiteParser->addWarning(generateErrors, S8Printf("Count cannot be negative. It must a number between -2 and 18 inclusive at '%s:%d'", xmlPath.c_str(), keyPos.getLine()));
return false;
}
if ( value() > 18 ) {
xmlLiteParser->addWarning(generateErrors, S8Printf("Count cannot > 18. It must a number between -2 and 18 inclusive at '%s:%d'", xmlPath.c_str(), keyPos.getLine()));
return false;
}
return true;
}
} Count = CountClass();
```
Returning false will put back the value to an undefined state.
In your dict, declare a member CountClass Count. If the value is out of range, Count will be undefined.
##### Validation of interdependent values
To check for consistency of values in a dict, you override the same validate method for your dict.
Imagine you have a dict containing a type (1 or 2) and a subType, but type 1 cannot have subtype. Type 2 may have subtype, and if there is, it must be 11 or 12. Example 4 :
```
class MyDictClass : public XmlDict
{
using super = XmlDict;
public:
MyXmlType type; // this is a subclass of XmlUInt8 that check that type is 1 or 2
MyXmlSubType subType; // this is a subclass of XmlUInt8 that check that subtype is 11 or 12
XmlString8 name; // as many other field that there is in this dict
if ( !super::validate(xmlLiteParser, xmlPath, keyPos, generateErrors) ) return false;
if ( !type.isDefined() ) {
xmlLiteParser->addWarning(generateErrors, S8Printf("Type must befined at '%s:%d'", xmlPath.c_str(), keyPos.getLine()));
return false;
}
if ( type.value() == 1 ) {
if ( subType.isDefined() ) {
xmlLiteParser->addWarning(generateErrors, S8Printf("Type 1 cannot have a subtype at '%s:%d'", xmlPath.c_str(), keyPos.getLine()));
return false;
}
}else if ( type.value() == 2 ) {
// nothing to do because subtype is optional, and if it exists, weknow that the value is correct because of th validation in MyXmlSubType
}else{
panic("There is a bug in MyXmlType::validate() !");
}
return true;
}
};
```
Returning false will put back the dict to an undefined state. Which means, in that case, the whole dict to be undefined as it wasn't at all in the XML file.
NOTE : it's possible to do the single field validation at dict level. The previous example could written as example 5 :
```
class MyDictClass : public XmlDict
{
using super = XmlDict;
public:
XmlUInt8 type; // no validation except that the value is an unsigned 8 bits int
XmlUInt8 subType; // no validation except that the value is an unsigned 8 bits int
XmlString8 name; // as many other field that there is in this dict
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plistversion="1.0">
<dict>
<key>KeyNameForBoolArray</key>
<array>
<true/>
<false/>
<true/>
... {as many as ther is}
</dict>
</dict>
```
Of course, you can create an XmlArray of a dict you created.
### Repeating dict
Until now, examples shown a dict that has a predefined set of keys. But you can have a dict that contains repeating key/value pair. The key could be any string.
For that, you have a template class XmlRepeatingDict. To create a dict that can contains a sequence of key and int32. Example 7 :
```
class MyDictClass : public ConfigPlistAbstractClass
Because a dict has to be a sequence of key and value, please note the use of the class XmlAddKey<XmlKey,XmlInt32>> that "adds" a key to a XmlInt32. You can replace XmlInt32 by any type the inherite from XmlAbstractType. That includes your own dicts and arrays.
The example above will parse a file like :
```
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plistversion="1.0">
<dict>
<key>KeyNameForKeyIntPairs</key>
<dict>
<key>a key</key>
<integer>1</integer>
<key>another key</key>
<integer>2</integer>
<key>third key</key>
<integer>3</integer>
</dict>
</dict>
```
After the dict is parsed, you can access values this way :
In this example, the value will be tried to be parsed as a XBool. If it doesn't work, the next possibility is tried. Here it's xmlString8. You can create union with any kind of field you create, including dict and arrays.