How do I iterate through the XmlObjectBase object
Question asked by Holger Schlüter - February 12 at 12:29 PM
I would like to iterate recursively through the object created by 
    XmlObjectBase elm = syncAXISConfigSchema_InternalLib.ClassFactory.FromXmlFile(filename);
I would like to display all generated classes in a tree similar to the SimpleViewer in the SampleApplication.
I am looking for a collection like elm.AllChildren

1 Reply

Reply to Thread
Holger Schlüter Replied
February 15 at 10:55 AM
I have been able to solve my problem using reflection.
Here is a code snippet that fills an XmlDocument (.NET) with the classnames of the tree:
        internal void ReadFile(string filename)
            object elm = syncAXISConfigSchema_InternalLib.ClassFactory.FromXmlFile(filename);
            XmlDocument xmlDocument = new XmlDocument();
            XmlElement element = xmlDocument.CreateElement(elm.GetType().Name);
            ReflectData(elm, xmlDocument);
        internal void ReflectData(object item, XmlDocument xmlDocument)
            Type type = item.GetType();
            foreach (PropertyInfo m in type.GetProperties())
                if (m.PropertyType.Namespace == "cfg")
                    var element = xmlDocument.CreateElement(m.PropertyType.Name);
                    var node = xmlDocument.SelectSingleNode("*");
                    object newItem = Activator.CreateInstance(m.PropertyType);
                    ReflectData(newItem, xmlDocument);

Reply to Thread