There are two subsystems that work together to make up the Document Services subsystem: The parser and the object hierarchy. These two subsystems make is possible to read a SVG document defined by a file into memory.
The parser is responsible for reading through all the elements in the XML file and creating the Sugar objects that will store the parsed information. The source for the parser can be found in the sugar/src/libsugar/parser directory.
The Sugar object hierarchy that represents the actual SVG document in memory. Its purpose is to provide an easy-to-use, robust interface that the rendering subsystems can utilize to retrieve information about the SVG document. The hierarchy of Sugar objects attempts to mimic the hierarchy contained in the original SVG document as closely as possible. The source for all the objects that can make up this hierarchy is contained in the sugar/src/libsugar/primitives directory.
All Sugar objects associated with a SVG document node that stores some attributes from that node inherits from the SugElement object. SugElement has a general way of storing arbitrary attributes, as well as accessor functions that retrieve these attributes as basic data types (such as color, string, integer, etc). The more specific Sugar objects are responsible for implementing accessor functions for more specific data types, if needed.
For the most part, there is a one to one match of SVG elements to Sugar objects: the <rect> has an associated SugRectElement object, <polygon> has SugPolygonElement, etc. There are no exceptions to this rule as of this writing, but that might change in the future.
These two systems work together as follows: The parser starts with the first node in the SVG document. It figures out what kind of node it is looking at, and creates the appropriate Sugar Object. The parser then goes through each attribute in the node and adds the information to the newly created Sugar object. After completing this task for the node, it then performs the same operations on the node's siblings and children. After the parser goes through the entire SVG document, the Sugar Object hierarchy should have an accurate representation of the parsed document stored in memory.