public virtual Data LoadData(IOid oid)
        {
            XDocument doc = XDocument.Load(XmlFile.GetFile(Filename(oid)).FullName);

            CollectionData collection = null;
            ObjectData     objectData = null;
            string         fieldName  = "";

            foreach (XElement element in doc.Descendants())
            {
                LoadNode(element, ref collection, ref objectData, ref fieldName);
            }

            if (objectData != null)
            {
                return(objectData);
            }
            if (collection != null)
            {
                return(collection);
            }
            throw new FindObjectException("No data found for " + oid + " (possible missing file)");
        }
        public void LoadNode(XElement Node, ref CollectionData collection, ref ObjectData objectData, ref string fieldName)
        {
            string tag = Node.Name.LocalName;

            if (objectData != null)
            {
                if (tag.Equals("value"))
                {
                    fieldName = Node.Attribute("field").Value;
                    objectData.SetField(fieldName, Node.Value);
                }
                else if (tag.Equals("inline"))
                {
                    CollectionData sinkCollection   = null;
                    ObjectData     inlineObjectData = null;
                    string         sinkName         = "";
                    fieldName = Node.Attribute("field").Value;
                    LoadNode(Node.Element("naked-object"), ref sinkCollection, ref inlineObjectData, ref sinkName);
                    objectData.SetField(fieldName, inlineObjectData);
                }
                else if (tag.Equals("association"))
                {
                    fieldName = Node.Attribute("field").Value;
                    long id = Convert.ToInt64(Node.Attribute("ref").Value, 16);
                    objectData.SetField(fieldName, SerialOid.CreatePersistent(id, Node.Attribute("Type").Value));
                }
                else if (tag.Equals("element"))
                {
                    long id = Convert.ToInt64(Node.Attribute("ref").Value, 16);
                    objectData.AddElement(fieldName, SerialOid.CreatePersistent(id, Node.Attribute("Type").Value));
                }
                else if (tag.Equals("multiple-association"))
                {
                    fieldName = Node.Attribute("field").Value;
                    objectData.InitCollection(fieldName);
                }
            }
            else if (collection != null)
            {
                if (tag.Equals("element"))
                {
                    long id = Convert.ToInt64(Node.Attribute("ref").Value, 16);
                    collection.AddElement(SerialOid.CreatePersistent(id, Node.Attribute("Type").Value));
                }
            }
            else
            {
                if (tag.Equals("naked-object"))
                {
                    string   type    = Node.Attribute("Type").Value;
                    string   user    = Node.Attribute("user").Value;
                    IVersion version = GetVersion(Node, user);
                    IOid     oid     = GetOid(Node, type);
                    INakedObjectSpecification spec = NakedObjectsContext.Reflector.LoadSpecification(type);

                    objectData = new ObjectData(spec, oid, version);
                }
                else if (tag.Equals("collection"))
                {
                    string type    = Node.Attribute("Type").Value;
                    long   version = Convert.ToInt64(Node.Attribute("ver").Value, 16);
                    string user    = Node.Attribute("user").Value;
                    long   id      = Convert.ToInt64(Node.Attribute("id").Value, 16);
                    INakedObjectSpecification spec = NakedObjectsContext.Reflector.LoadSpecification(type);
                    IOid oid = SerialOid.CreatePersistent(id, type);
                    collection = new CollectionData(spec, oid, new FileVersion(user, version));
                }
                else
                {
                    throw new XmlException("Invalid data");
                }
            }
        }
        public void LoadNode(XElement Node, ref CollectionData collection, ref ObjectData objectData, ref string fieldName) {
            string tag = Node.Name.LocalName;
            if (objectData != null) {
                if (tag.Equals("value")) {
                    fieldName = Node.Attribute("field").Value;
                    objectData.SetField(fieldName, Node.Value);
                }
                else if (tag.Equals("inline")) {
                    CollectionData sinkCollection = null;
                    ObjectData inlineObjectData = null;
                    string sinkName = "";
                    fieldName = Node.Attribute("field").Value;
                    LoadNode(Node.Element("naked-object"), ref sinkCollection, ref inlineObjectData, ref sinkName);
                    objectData.SetField(fieldName, inlineObjectData);
                }
                else if (tag.Equals("association")) {
                    fieldName = Node.Attribute("field").Value;
                    long id = Convert.ToInt64(Node.Attribute("ref").Value, 16);
                    objectData.SetField(fieldName, SerialOid.CreatePersistent(id, Node.Attribute("Type").Value));
                }
                else if (tag.Equals("element")) {
                    long id = Convert.ToInt64(Node.Attribute("ref").Value, 16);
                    objectData.AddElement(fieldName, SerialOid.CreatePersistent(id, Node.Attribute("Type").Value));
                }
                else if (tag.Equals("multiple-association")) {
                    fieldName = Node.Attribute("field").Value;
                    objectData.InitCollection(fieldName);
                }
            }
            else if (collection != null) {
                if (tag.Equals("element")) {
                    long id = Convert.ToInt64(Node.Attribute("ref").Value, 16);
                    collection.AddElement(SerialOid.CreatePersistent(id, Node.Attribute("Type").Value));
                }
            }
            else {
                if (tag.Equals("naked-object")) {
                    string type = Node.Attribute("Type").Value;
                    string user = Node.Attribute("user").Value;
                    IVersion version = GetVersion(Node, user);
                    IOid oid = GetOid(Node, type);
                    INakedObjectSpecification spec = NakedObjectsContext.Reflector.LoadSpecification(type);

                    objectData = new ObjectData(spec, oid, version);
                }
                else if (tag.Equals("collection")) {
                    string type = Node.Attribute("Type").Value;
                    long version = Convert.ToInt64(Node.Attribute("ver").Value, 16);
                    string user = Node.Attribute("user").Value;
                    long id = Convert.ToInt64(Node.Attribute("id").Value, 16);
                    INakedObjectSpecification spec = NakedObjectsContext.Reflector.LoadSpecification(type);
                    IOid oid = SerialOid.CreatePersistent(id, type);
                    collection = new CollectionData(spec, oid, new FileVersion(user, version));
                }
                else {
                    throw new XmlException("Invalid data");
                }
            }
        }