-
Notifications
You must be signed in to change notification settings - Fork 0
Allowed XML format
The parser expects you to have a context backed up by a persistent storage coordinator which has a model and at least one storage. The parser doesn't care what the storage type is as long as model and storage conform to each other. Model must include all objects, relationships and object attributes that you want to store into your database. Otherwise the parser will silently ignore them.
These equal managed objects. Since the parser doesn't use a temporary storage for items, the object must include the object id as XML attribute. This way we can fetch or create an object immediately into the context which we populate from the XML. An object contains relationships and object attributes.
Relationship is between two objects. I'm also thinking of you being allowed to set type of an object with an XML attribute since this might lead to more relaxed XML. Relationship must not directly contain attributes. If a relationship is to-one, a separate relationship container is not to be used. The single element counts as both a relationship and the corresponding object. If the relationship is to-one, the id as XML attribute rule from object applies. If the relationship is to-many, you need a special container, or in other words a relationship element, around the objects to which the relationship refers to.
An object attribute must not contain relationships or objects ever. They contain objective C bases types. Because of certain type issues, parser does explicit type conversions if the type is NSInteger or NSDate so that NSManagedObject remains happy. Probably a better way to do it would be to write methods to allow always setting the variables via strings and the Managed Object itself would do the type conversion. This approach would have the drawback, however, that you'd need to extend the Managed Objects and simply graphically writing a model would not be sufficient.
Note that the first container element is deleted since it's not bound to any object. <title>My book on XML</title> Yada yada More boring stuff</content <title>A very short book</title> I'm the only page in the book Here obvious Book and Page are objects, pages is a relation, page in one particular context is a relationship and content and title are object attributes; id is actually used as object attribute as well in the actual Managed Object so it's an XML attribute before it's parsed and turns into an object attribute after parsing. Because of limitations of Objective C the name is only id as XML attribute and it gets translated as ident when it becomes an object attribute.