# ZAPD extraction notes Okay, I hand ZAPD a binary file and an XML... ## ZAPD parses the XML For each XML node, it calls the corresponding `ExtractFromXML` of each `ZResource` `ExtractFromXML`: - Calls `ParseXML`. This is where the `ZResource` reads the extra XML attributes - Calls `ParseRawData`. This is where it parses the raw binary file - It should also declare a placeholder `Declaration` with `AddDeclaration` family of methods ? What about `DeclareVar`? - `DeclareVar` is in charge of calling the corresponding any of the `AddDeclaration` family of methods `DeclareReferences`: When ZAPD had finished iterating over the XML, it calls `DeclareReferences` for each `ZResource` it has - DeclareReferences is where a ZResource can declare any other resource it found when parsing the binary data - For example, a `ZLimb` would declare the corresponding dlists there ? ZAPD then iterates over each new `ZResource` declared in this way? - Yes, it does the following - ```c++ void ZFile::DeclareResourceSubReferences() { for (size_t i = 0; i < resources.size(); i++) { resources.at(i)->DeclareReferences(name); } } ``` - So, if a `ZResource` adds new resources in its `DeclareReferences`, then ZAPD will call `DeclareReferences` for that new resource added eventually. ? Repeat until it has traversed the entire tree of declared resources? After ZAPD iterates over each `ZResource`, it does some stuff to calculate unaccounteds, calls `GetSourceOutputCode` for every `ZResource`, and stuff like that ? What about `GetBodySourceCode`? - Each `ZResource` is responsible for calling its own (or others) `GetBodySourceCode` method And then it generates the C file