I wrote the following maybe...2 years ago? I've put the actual software into production and have demonstrated it in a classroom environment. The initial thinking here was to bridge the gap between SOAP and OOP. As of now, unless something has changed, web services doesn't support this sort of thing, nor does SOAP on any platform.
So....I came up with this. Guess what? I could use this for a lot of other things as it's so generic, you can use it for just about anything from config files to email exceptions from errors, resource scripts for languages, private label stuff, etc.
Does anyone give a freakin' dang? I guess not as no professor paid one bit of attention to it, no collegiete director, no PM, no client of any staffing firm, or any other recruiter. I've emailed this document to a load of people, and I think nobody understands it. If I had someone to do this the same way on a Java basis, you could readily integrate cross platform stuff using OOP, and there is a demand for it. Then again, I'm just some long haired freak who wears high dollar silk shirts to work with funky colors, and I run numbers and engineering through my head all day long. I see the whole picture like a kid with legos. I see the pieces and the final result.
For some reason, that's a very bad thing-particularly around my neck of the woods. /:)
So without further ado, here is the copy and paste version from MS Word of what I plan on using for my Mob Manager tool. This is my code, and my documentation.
XML API
Introduction
This documentation is to outline the XML Object API. The purpose of the API is to allow a developer to create, serialize, and populate user defined objects using XML. This functionality has a wide variety of applications, and can be used nearly anywhere that XML is used.
Let's assume we have a given object, and we wish to save it as XML.
using System;
using System.Collections.Generic;
using System.Text;
using System.Reflection;
namespace TestObject
{
public class MyObject
{
private int m_int;
private string m_myString="";
public MyObject()
{
//Add additional constructor stuff here.
}
public int MyInteger
{
get{return this.m_int;}
set{m_int=value;}
}
public string MyString
{
get { return m_myString; }
set { m_myString = value; }
}
~MyObject()
{
m_myString="";
m_myString=null;
}
}
}
Fig 0.1-1
We can always write a custom parser to load XML, and to create some sort of schema that saves XML to a file. We can do that each any every time we write a class.
If we inherit the RuntimeXML class from the XML Object API, we have this functionality built in already. The RuntimeXML base class has everything we need to populate an object from XML, save it to XML, or pass in a properly formatted XML document to populate our object when we instantiate it.
using System;
using System.Collections.Generic;
using System.Text;
using System.Reflection;
using XML_Utilities;
namespace TestObject
{
public class MyObject : RuntimeXML
{
public static int intInstances;
private int m_int;
private string m_myString="";
public MyObject()
{
//Add additional constructor stuff here.
}
//This populates the current instance with data based \
//on the XML we provide it with.
public MyObject(string strXML)
{
//We explicitly define the type to pass in as
//the type of objec this is.
this.CreateFromXML(strXML,typeof(MyObject));
}
public int MyInteger
{
get{return this.m_int;}
set{m_int=value;}
}
public string MyString
{
get { return m_myString; }
set { m_myString = value; }
}
~MyObject()
{
m_myString="";
m_myString=null;
}
}
}
Fig 0.1-2
Criteria
In order to best make use of the XML Object API, there are some criteria/guidelines that you should follow and implement in your code to avoid problems and make the best use from the API.
NOTES:
1.0 Functions and methods within the RuntimeXML Class.
1.1. CreateFromXML
There are 2 different overloaded types within the base class.
virtual public void CreateFromXML(string strXML,Type t)
virtual public void CreateFromXML(string strXML, Type t, Dictionary<object, object> Objects)
These methods live within the RuntimeXML base class. They populate an instance of an object that inherits this class from the XML that you pass to it, the type, and if there are other user defined types nested within your object, you need to use the latter of the two.
strXML
This is the XML document describing your object, and all it's public properties as a string.
t
T is the type of object you are wanting to create. You can obtain this by using the GetType method of a given object. GetType returns a System.Type object, which is what this function uses.
Type Example
CreateFromXML(strXML,typeof(MyObject));
CreateFromXML(strXML,m_object.GetType());
You can use either typeof([Object_Name]) or [Object_Name].GetType() to obtain a System.Type object for use in this method.
Objects
In the event that you have other user defined or non-primitive types of objects nested in your code, you need to pass in a dictionary collection of those types of objects. The XML Object API doesn't know what type of object it will need to create and does not understand ProgID's like COM does. It does understand fully qualified names, and it can use references to certain objects.
When passing in a dictionary object, the name of the object should be a string type, and an instance of an object for reference by the API.
Objects Example
Dictionary<object, object> oDict = new Dictionary<object, object>();
oDict.Add("TestObject.TestRecursive",new TestObject.TestRecursive());
oDict.Add("TestObject.MyObject", new TestObject.MyObject());
oDict.Add("TestObject.TestWidget", new TestObject.TestWidget());
Fig 1.2-1
The code in the above figure illustrates how you should create the dictionary object to pass in. The dictionary should only consist of user defined types that inherit a base class defined in the XML Object API. The first argument should be the fully qualified name as a string, and the value should be some instance of the object that the API might encounter at runtime.
NOTES:
1.2. CreateXML
public string CreateXML(Type t)
public string CreateXML(Type t, Dictionary<object, object> Objects)
This creates an XML document that describes your object at runtime. Your custom object will dynamically discover it's own properties at runtime and obtain information as to the property name, type, and value.
The first declaration is for primitives, and the second is for objects that have other user defined types within them.
t
T is the type of object you want to populate. You can obtain this by using the GetType method of a given object. GetType returns a System.Type object, which is what this function uses.
Type Example
CreateXML(typeof(MyObject));
CreateXML(m_object.GetType());
You can use either typeof([Object_Name]) or [Object_Name].GetType() to obtain a System.Type object for use in this method.
Objects
In the event that you have other user defined or non-primative types of objects nested in your code, you need to pass in a dictionary collection of those types of objects. The XML Object API doesn't know what type of object it will need to create and does not understand ProgID's like COM does. It does understand fully qualified names, and it can use references to certain objects.
When passing in a dictionary object, the name of the object should be a string type, and an instance of an object for reference by the API.
Objects Example
Dictionary<object, object> oDict = new Dictionary<object, object>();
oDict.Add("TestObject.TestRecursive",new TestObject.TestRecursive());
oDict.Add("TestObject.MyObject", new TestObject.MyObject());
oDict.Add("TestObject.TestWidget", new TestObject.TestWidget());
Fig 1.3-1
The code in the above figure illustrates how you should create the dictionary object to pass in. The dictionary should only consist of user defined types that inherit a base class defined in the XML Object API. The first argument should be the fully qualified name as a string, and the value should be some instance of the object that the API might encounter at runtime.
Usage Example
TestObject.MyObject oTest = new TestObject.MyObject();
Dictionary<object, object> oDict = new Dictionary<object, object>();
oDict.Add("TestObject.TestRecursive",new TestObject.TestRecursive());
oDict.Add("TestObject.MyObject", new TestObject.MyObject());
oDict.Add("TestObject.TestWidget", new TestObject.TestWidget());
string strXML=oTest.CreateXML(typeof(TestObject.MyObject),oDict);
Fig 1.3-2
This illustrates how to create the XML from a custom object at runtime. The result is returned to strXML as a string. The string has the XML that explicitly describes the object.
NOTES:
1.3. Load
virtual public string Load(string strFileName)
This loads an XML document, reads the entire file, and returns a string representation of the XML within the document. You must provide the complete file path as well as the file name for strFileName.
If your file is invalid, or doesn't exist, an exception will be thrown. The inner workings of this function uses a file stream reader object.
Usage Example
oTest = new TestObject.MyObject();
strXML = oTest.Load(Application.StartupPath + "\\Test Object.xml");
oTest.CreateFromXML(strXML,oTest.GetType(),oDict);
strXML = oTest.CreateXML(oTest.GetType(), oDict);
oTest.SaveXML(Application.StartupPath + "\\Test Object from file.xml",strXML);
Fig 1.4-1
This illustrates how to load an XML file using the Load function. The file is read, and it returns a string representaiton of the XML descibing a user defined object. The XML can then be used and manipulated to populate the object using the CreateFromXML method.
NOTE:
1.4. SaveXML
virtual public void SaveXML(string strFileName, string strXMLDoc)
virtual public void SaveXML(Type t, Object o,string strFileName)
These methods save XML files that explicitly describe your document. Each overloaded declaration works differently from the next one.
If you have a copy of the XML string that describes your object, you can pass that in along with a file name. The file name should include the complete path of your file as well as the filename itself. This uses a stream writer object when invoked to create the XML file.
NOTES:
The second function makes an internal call to the CreateXML function for an object of type t, from instance o. It then takes that XML, and passes it to the first function to save it to a file. There is no support for a function to serialize XML to a file whose XML is not known, and who's object has other user defined objects within it. Future versions or releases may support this. Therefore, it is suggested to use the first function if possible.
t
T is the type of object you want to populate. You can obtain this by using the GetType method of a given object. GetType returns a System.Type object, which is what this function uses.
Type Example
SaveXML(typeof(MyObject), m_object,strFileName);
SaveXML(m_object.GetType(), m_object,strFileName);
You can use either typeof([Object_Name]) or [Object_Name].GetType() to obtain a System.Type object for use in this method.
Objects
In the event that you have other user defined or non-primitive types of objects nested in your code, you need to pass in a dictionary collection of those types of objects. The XML Object API doesn't know what type of object it will need to create and does not understand ProgID's like COM does. It does understand fully qualified names, and it can use references to certain objects.
When passing in a dictionary object, the name of the object should be a string type, and an instance of an object for reference by the API.
Objects Example
Dictionary<object, object> oDict = new Dictionary<object, object>();
oDict.Add("TestObject.TestRecursive",new TestObject.TestRecursive());
oDict.Add("TestObject.MyObject", new TestObject.MyObject());
oDict.Add("TestObject.TestWidget", new TestObject.TestWidget());
Fig 1.5-1
Usage example
string strXML=oTest.CreateXML(typeof(TestObject.MyObject),oDict);
//Save the file as XML
oTest.SaveXML(Application.StartupPath + "\\Test Object.xml", strXML);
oTest.Dispose();
oTest = null;
Fig 1.5-2
The above illustration demonstrates how to create an XML document using the CreateXML method. From there, you pass that string into the SaveXML method. The complete path is determined dynamically at runtime and concatenated with the actual file name.
NOTE:
1.5. Dispose
public void Dispose()
This function is inhertiable by your custom object, and is a standard implementation of the IDisposable interface. While the class RuntimeXML doesn't implement this particular interface, the functionality is the same.
NOTE:
2.0 Functions and methods within the ArrayListRuntimeXML Class.
This class is derived in part from ArrayList. ArrayList is parent object from which objects within this class originate from.
2.1 Constructors
public ArrayListRuntimeXML()
public ArrayListRuntimeXML(string strXML,ArrayListXML oList, Dictionary<object,object> Objects)
The first constructor is a standard default contstructor. If you wish to populate your ArrayList from an XML document, and your array has other custom user defined types, the second constructor exists for that reason.
strXML
This is the XML document describing your object, and all it's public properties as a string.
oList
This is an ArrayListXML class. Since classes are passed by reference vs. value in .NET, an empty instance can be passed in.
Objects
In the event that you have other user defined or non-primitive types of objects nested in your code, you need to pass in a dictionary collection of those types of objects. The XML Object API doesn't know what type of object it will need to create and does not understand ProgID's like COM does. It does understand fully qualified names, and it can use references to certain objects.
When passing in a dictionary object, the name of the object should be a string type, and an instance of an object for reference by the API.
Objects Example
Dictionary<object, object> oDict = new Dictionary<object, object>();
oDict.Add("TestObject.TestRecursive",new TestObject.TestRecursive());
oDict.Add("TestObject.MyObject", new TestObject.MyObject());
oDict.Add("TestObject.TestWidget", new TestObject.TestWidget());
Fig 2.1-2
2.2. CreateFromXML
There are 2 different overloaded types within the base class.
virtual public void CreateFromXML(string strXML, ArrayList oList)
virtual public void CreateFromXML(string strXML,ArrayList oList, Dictionary<object,object> Objects)
These methods live within the ArrayListXML base class. They populate an instance of an object that inherits this class from the XML that you pass to it, the type, and if there are other user defined types nested within your object, you need to use the latter of the two.
strXML
This is the XML document describing your object, and all it's public properties as a string.
oList
This is an array list that you want to pass in, or it can be a type of ArrayListXML class. Array list inherits from the ArrayList class, so you can pass that in since the base type matches the interface argument.
Objects
In the event that you have other user defined or non-primitive types of objects nested in your code, you need to pass in a dictionary collection of those types of objects. The XML Object API doesn't know what type of object it will need to create and does not understand ProgID's like COM does. It does understand fully qualified names, and it can use references to certain objects.
When passing in a dictionary object, the name of the object should be a string type, and an instance of an object for reference by the API.
Objects Example
Dictionary<object, object> oDict = new Dictionary<object, object>();
oDict.Add("TestObject.TestRecursive",new TestObject.TestRecursive());
oDict.Add("TestObject.MyObject", new TestObject.MyObject());
oDict.Add("TestObject.TestWidget", new TestObject.TestWidget());
Fig 2.2-1
The code in the above figure illustrates how you should create the dictionary object to pass in. The dictionary should only consist of user defined types that inherit a base class defined in the XML Object API. The first argument should be the fully qualified name as a string, and the value should be some instance of the object that the API might encounter at runtime.
Usage Example
oArrayXML = new XML_Utilities.ArrayListXML();
strXMLDoc = oArrayXML.Load(Application.StartupPath + "\\Test Array List.xml");
oArrayXML.CreateFromXML(strXMLDoc, oArrayXML,oObjects);
oArrayXML.SaveXML(Application.StartupPath + "\\Test Array List from file.xml", oArrayXML.CreateXML(oArrayXML, oObjects));
//Save the file as XML
oArrayXML = null;
Fig 2.2-2
This illustrates how to use the CreateFromXML method. The XML is obtained by loading a file, and the resulting string is passed into the argument. The object oArrayXML is then populated based on the data passed into it.
NOTES:
2.3. CreateXML
virtual public string CreateXML(ArrayList oList)
virtual public string CreateXML(ArrayList oList, Dictionary<object, object> Objects)
This creates an XML document that describes your object at runtime. Your custom object will dynamically discover it's own properties at runtime and obtain information as to the property name, type, and value.
The first declaration is for primitives, and the second is for objects that have other user defined types within them.
oList
This is an array list that you want to pass in, or it can be a type of ArrayListXML class. Array list inherits from the ArrayList class, so you can pass that in since the base type matches the interface argument.
Objects
In the event that you have other user defined or non-primative types of objects nested in your code, you need to pass in a dictionary collection of those types of objects. The XML Object API doesn't know what type of object it will need to create and does not understand ProgID's like COM does. It does understand fully qualified names, and it can use references to certain objects.
When passing in a dictionary object, the name of the object should be a string type, and an instance of an object for reference by the API.
Objects Example
Dictionary<object, object> oDict = new Dictionary<object, object>();
oDict.Add("TestObject.TestRecursive",new TestObject.TestRecursive());
oDict.Add("TestObject.MyObject", new TestObject.MyObject());
oDict.Add("TestObject.TestWidget", new TestObject.TestWidget());
Fig 2.3-1
The code in the above figure illustrates how you should create the dictionary object to pass in. The dictionary should only consist of user defined types that inherit a base class defined in the XML Object API. The first argument should be the fully qualified name as a string, and the value should be some instance of the object that the API might encounter at runtime.
Usage Example
Dictionary<object, object> oObjects = new Dictionary<object, object>();
oObjects.Add("TestObject.MyObject", new TestObject.MyObject());
oObjects.Add("TestObject.TestRecursive",new TestObject.TestRecursive());
string strXMLDoc = oArrayXML.CreateXML(oArrayXML,oObjects);
Fig 2.3-2
This illustrates how to create the XML from a custom object at runtime. The result is returned to strXML as a string. The string has the XML that explicitly describes the object.
NOTES:
2.4. Load
virtual public string Load(string strFileName)
This loads an XML document, reads the entire file, and returns a string representation of the XML within the document. You must provide the complete file path as well as the file name for strFileName.
If your file is invalid, or doesn't exist, an exception will be thrown. The inner workings of this function uses a file stream reader object.
Usage Example
Dictionary<object, object> oObjects = new Dictionary<object, object>();
oObjects.Add("TestObject.MyObject", new TestObject.MyObject());
oObjects.Add("TestObject.TestRecursive",new TestObject.TestRecursive());
oArrayXML = new XML_Utilities.ArrayListXML();
strXMLDoc = oArrayXML.Load(Application.StartupPath + "\\Test Array List.xml");
oArrayXML.CreateFromXML(strXMLDoc, oArrayXML,oObjects);
oArrayXML.SaveXML(Application.StartupPath + "\\Test Array List from file.xml", oArrayXML.CreateXML(oArrayXML, oObjects));
//Save the file as XML
oArrayXML = null;
Fig 2.4-1
This illustrates how to load an XML file using the Load function. The file is read, and it returns a string representaiton of the XML descibing a user defined object. The XML can then be used and manipulated to populate the object using the CreateFromXML method.
NOTE:
2.5. SaveXML
virtual public void SaveXML(string strFileName, string strXMLDoc)
virtual public void SaveXML(Type t, Object o,string strFileName)
These methods save XML files that explicitly describe your document. Each overloaded declaration works differently from the next one.
If you have a copy of the XML string that describes your object, you can pass that in along with a file name. The file name should include the complete path of your file as well as the filename itself. This uses a stream writer object when invoked to create the XML file.
NOTES:
The second function makes an internal call to the CreateXML function for an object of type t, from instance o. It then takes that XML, and passes it to the first function to save it to a file. There is no support for a function to serialize XML to a file whose XML is not known, and who's object has other user defined objects within it. Future versions or releases may support this. Therefore, it is suggested to use the first function if possible.
t
T is the type of object you want to populate. You can obtain this by using the GetType method of a given object. GetType returns a System.Type object, which is what this function uses.
Type Example
SaveXML(typeof(MyObject), m_object,strFileName);
SaveXML(m_object.GetType(), m_object,strFileName);
You can use either typeof([Object_Name]) or [Object_Name].GetType() to obtain a System.Type object for use in this method.
Objects
In the event that you have other user defined or non-primitive types of objects nested in your code, you need to pass in a dictionary collection of those types of objects. The XML Object API doesn't know what type of object it will need to create and does not understand ProgID's like COM does. It does understand fully qualified names, and it can use references to certain objects.
When passing in a dictionary object, the name of the object should be a string type, and an instance of an object for reference by the API.
Objects Example
Dictionary<object, object> oDict = new Dictionary<object, object>();
oDict.Add("TestObject.TestRecursive",new TestObject.TestRecursive());
oDict.Add("TestObject.MyObject", new TestObject.MyObject());
oDict.Add("TestObject.TestWidget", new TestObject.TestWidget());
Fig 2.5-1
Usage Example
Dictionary<object, object> oObjects = new Dictionary<object, object>();
oObjects.Add("TestObject.MyObject", new TestObject.MyObject());
oObjects.Add("TestObject.TestRecursive",new TestObject.TestRecursive());
oArrayXML = new XML_Utilities.ArrayListXML();
strXMLDoc = oArrayXML.Load(Application.StartupPath + "\\Test Array List.xml");
oArrayXML.CreateFromXML(strXMLDoc, oArrayXML,oObjects);
oArrayXML.SaveXML(Application.StartupPath + "\\Test Array List from file.xml", oArrayXML.CreateXML(oArrayXML, oObjects));
//Save the file as XML
oArrayXML = null;
Fig 2.5-2
The above illustration demonstrates how to create an XML document using the CreateXML method. From there, you pass that string into the SaveXML method. The complete path is determined dynamically at runtime and concatenated with the actual file name.
3.0 Functions and methods within the ListRuntimeXML Class.
This class is derived in part from List. List is parent object from which objects within this class originate from. Although List is a typed list, that functionality more or less vanishes as the implementation of this class uses type Object. There is no guarentee are runtime as to what exacty type of object will be used, therefore there was no alternative to this sort of implementation.
3.1 Constructors
public ListRuntimeXML()
public ListRuntimeXML(string strXML, List<Object> oList)
The first constructor is a standard default contstructor. If you wish to populate your List from an XML document, and you have some instance of a list or ListXML object that is the target for population, the latter of the 2 suits this purpose.
strXML
This is the XML document describing your object, and all it's public properties as a string.
oList
This is a List class. Since classes are passed by reference vs. value in .NET, an empty instance can be passed in.
3.2. CreateFromXML
There are 2 different overloaded types within the base class.
virtual public void CreateFromXML(string strXML, List<Object> oList)
virtual public void CreateFromXML(string strXML, List<Object> oList, Dictionary<object, object> Objects)
These methods live within the ListXML base class. They populate an instance of an object that inherits this class from the XML that you pass to it, the type, and if there are other user defined types nested within your object, you need to use the latter of the two.
strXML
This is the XML document describing your object, and all it's public properties as a string.
oList
This is an array list that you want to pass in, or it can be a type of ListXML class. Array list inherits from the List class, so you can pass that in since the base type matches the interface argument.
Objects
In the event that you have other user defined or non-primitive types of objects nested in your code, you need to pass in a dictionary collection of those types of objects. The XML Object API doesn't know what type of object it will need to create and does not understand ProgID's like COM does. It does understand fully qualified names, and it can use references to certain objects.
When passing in a dictionary object, the name of the object should be a string type, and an instance of an object for reference by the API.
Objects Example
Dictionary<object, object> oDict = new Dictionary<object, object>();
oDict.Add("TestObject.TestRecursive",new TestObject.TestRecursive());
oDict.Add("TestObject.MyObject", new TestObject.MyObject());
oDict.Add("TestObject.TestWidget", new TestObject.TestWidget());
Fig 3.2-1
The code in the above figure illustrates how you should create the dictionary object to pass in. The dictionary should only consist of user defined types that inherit a base class defined in the XML Object API. The first argument should be the fully qualified name as a string, and the value should be some instance of the object that the API might encounter at runtime.
Usage Example
Dictionary<object, object> oObjects = new Dictionary<object, object>();
oObjects.Add("TestObject.MyObject", new TestObject.MyObject());
oObjects.Add("TestObject.TestRecursive", new TestObject.TestRecursive());
oListXML = new XML_Utilities.ListXML();
strXMLDoc = oListXML.Load(Application.StartupPath + "\\Test Typed List.xml");
oListXML.CreateFromXML(strXMLDoc,oListXML, oObjects);
oListXML.SaveXML(Application.StartupPath + "\\Test Typed List from file.xml", oListXML.CreateXML(oListXML, oObjects));
//Save the file as XML
oListXML = null;
Fig 3.2-2
This illustrates how to use the CreateFromXML method. The XML is obtained by loading a file, and the resulting string is passed into the argument. The object oArrayXML is then populated based on the data passed into it.
NOTES:
3.3. CreateXML
virtual public string CreateXML(List<Object> oList)
virtual public string CreateXML(List<Object> oList, Dictionary<object, object> Objects)
This creates an XML document that describes your object at runtime. Your custom object will dynamically discover it's own properties at runtime and obtain information as to the property name, type, and value.
The first declaration is for primitives, and the second is for objects that have other user defined types within them.
oList
This is an array list that you want to pass in, or it can be a type of ListXML class. List inherits from the List class, so you can pass that in since the base type matches the interface argument.
Objects
In the event that you have other user defined or non-primative types of objects nested in your code, you need to pass in a dictionary collection of those types of objects. The XML Object API doesn't know what type of object it will need to create and does not understand ProgID's like COM does. It does understand fully qualified names, and it can use references to certain objects.
When passing in a dictionary object, the name of the object should be a string type, and an instance of an object for reference by the API.
Objects Example
Dictionary<object, object> oDict = new Dictionary<object, object>();
oDict.Add("TestObject.TestRecursive",new TestObject.TestRecursive());
oDict.Add("TestObject.MyObject", new TestObject.MyObject());
oDict.Add("TestObject.TestWidget", new TestObject.TestWidget());
Fig 3.3-1
The code in the above figure illustrates how you should create the dictionary object to pass in. The dictionary should only consist of user defined types that inherit a base class defined in the XML Object API. The first argument should be the fully qualified name as a string, and the value should be some instance of the object that the API might encounter at runtime.
Usage Example
Dictionary<object, object> oObjects = new Dictionary<object, object>();
oObjects.Add("TestObject.MyObject", new TestObject.MyObject());
oObjects.Add("TestObject.TestRecursive",new TestObject.TestRecursive());
string strXMLDoc = oListXML.CreateXML(oListXML,oObjects);
Fig 3.3-2
This illustrates how to create the XML from a custom object at runtime. The result is returned to strXML as a string. The string has the XML that explicitly describes the object.
NOTES:
3.4. Load
virtual public string Load(string strFileName)
This loads an XML document, reads the entire file, and returns a string representation of the XML within the document. You must provide the complete file path as well as the file name for strFileName.
If your file is invalid, or doesn't exist, an exception will be thrown. The inner workings of this function uses a file stream reader object.
Usage Example
Dictionary<object, object> oObjects = new Dictionary<object, object>();
oObjects.Add("TestObject.MyObject", new TestObject.MyObject());
oObjects.Add("TestObject.TestRecursive",new TestObject.TestRecursive());
oListXML = new XML_Utilities.ListXML();
strXMLDoc = oListXML.Load(Application.StartupPath + "\\Test Typed List.xml");
oListXML.CreateFromXML(strXMLDoc,oListXML, oObjects);
oListXML.SaveXML(Application.StartupPath + "\\Test Typed List from file.xml", oListXML.CreateXML(oListXML, oObjects));
//Save the file as XML
oListXML = null;
Fig 3.4-1
This illustrates how to load an XML file using the Load function. The file is read, and it returns a string representaiton of the XML descibing a user defined object. The XML can then be used and manipulated to populate the object using the CreateFromXML method.
NOTE:
3.5. SaveXML
virtual public void SaveXML(string strFileName, string strXMLDoc)
virtual public void SaveXML(Type t, Object o,string strFileName)
These methods save XML files that explicitly describe your document. Each overloaded declaration works differently from the next one.
If you have a copy of the XML string that describes your object, you can pass that in along with a file name. The file name should include the complete path of your file as well as the filename itself. This uses a stream writer object when invoked to create the XML file.
NOTES:
The second function makes an internal call to the CreateXML function for an object of type t, from instance o. It then takes that XML, and passes it to the first function to save it to a file. There is no support for a function to serialize XML to a file whose XML is not known, and who's object has other user defined objects within it. Future versions or releases may support this. Therefore, it is suggested to use the first function if possible.
t
T is the type of object you want to populate. You can obtain this by using the GetType method of a given object. GetType returns a System.Type object, which is what this function uses.
Type Example
SaveXML(typeof(MyObject), m_object,strFileName);
SaveXML(m_object.GetType(), m_object,strFileName);
You can use either typeof([Object_Name]) or [Object_Name].GetType() to obtain a System.Type object for use in this method.
Objects
In the event that you have other user defined or non-primitive types of objects nested in your code, you need to pass in a dictionary collection of those types of objects. The XML Object API doesn't know what type of object it will need to create and does not understand ProgID's like COM does. It does understand fully qualified names, and it can use references to certain objects.
When passing in a dictionary object, the name of the object should be a string type, and an instance of an object for reference by the API.
Objects Example
Dictionary<object, object> oDict = new Dictionary<object, object>();
oDict.Add("TestObject.TestRecursive",new TestObject.TestRecursive());
oDict.Add("TestObject.MyObject", new TestObject.MyObject());
oDict.Add("TestObject.TestWidget", new TestObject.TestWidget());
Fig 3.5-1
Usage Example
Dictionary<object, object> oObjects = new Dictionary<object, object>();
oObjects.Add("TestObject.MyObject", new TestObject.MyObject());
oObjects.Add("TestObject.TestRecursive",new TestObject.TestRecursive());
oListXML = new XML_Utilities.ListXML();
strXMLDoc = oListXML.Load(Application.StartupPath + "\\Test Typed List.xml");
oListXML.CreateFromXML(strXMLDoc,oListXML, oObjects);
oListXML.SaveXML(Application.StartupPath + "\\Test Typed List from file.xml", oListXML.CreateXML(oListXML, oObjects));
//Save the file as XML
oListXML = null;
Fig 3.5-2
The above illustration demonstrates how to create an XML document using the CreateXML method. From there, you pass that string into the SaveXML method. The complete path is determined dynamically at runtime and concatenated with the actual file name.
4.0 Functions and methods within the DictionaryRuntimeXML Class.
This class is derived in part from Dictionary. Dictionary is parent object from which objects within this class originate from.
4.1 Constructors
public DictionaryRuntimeXML ()
public DictionaryRuntimeXML (string strXML, Dictionary<Object, Object> oDictonary)
The first constructor is a standard default contstructor. If you wish to populate your List from an XML document, and you have some instance of a list or ListXML object that is the target for population, the latter of the 2 suits this purpose.
strXML
This is the XML document describing your object, and all it's public properties as a string.
oDictonary
This is a Dictionary class. Since classes are passed by reference vs. value in .NET, an empty instance can be passed in to this constructor.
4.2. CreateFromXML
There are 3 different overloaded types within the base class.
virtual public void CreateFromXML(string strXML, Dictionary<Object,Object> oDictonary)
virtual public void CreateFromXML(string strXML, ref Dictionary<Object, Object> oDictonary, Dictionary<Object,Object> Objects)
*virtual public void CreateFromXML(string strXML, Dictionary<Object, Object> oDictonary, bool bUDT)
These methods live within the DictionaryXML base class. They populate an instance of an object that inherits this class from the XML that you pass to it, the type, and if there are other user defined types nested within your object, you need to use the latter of the two.
If you are using any user defined types at all anywhere within your object, or a tree if you're nesting user types, you need to explicitly pass a reference of your DictionaryXML object by reference. The reason for this is because it is the only means to force things to update internally, and they need a reference to an instance of your custom object as opposed to an instance.
strXML
This is the XML document describing your object, and all it's public properties as a string.
oDictonary
This is a Dictionary class. Since classes are passed by reference vs. value in .NET, an empty instance can be passed in to this method.
Objects
In the event that you have other user defined or non-primitive types of objects nested in your code, you need to pass in a dictionary collection of those types of objects. The XML Object API doesn't know what type of object it will need to create and does not understand ProgID's like COM does. It does understand fully qualified names, and it can use references to certain objects.
When passing in a dictionary object, the name of the object should be a string type, and an instance of an object for reference by the API.
Objects Example
Dictionary<object, object> oDict = new Dictionary<object, object>();
oDict.Add("TestObject.TestRecursive",new TestObject.TestRecursive());
oDict.Add("TestObject.MyObject", new TestObject.MyObject());
oDict.Add("TestObject.TestWidget", new TestObject.TestWidget());
Fig 4.2-1
The code in the above figure illustrates how you should create the dictionary object to pass in. The dictionary should only consist of user defined types that inherit a base class defined in the XML Object API. The first argument should be the fully qualified name as a string, and the value should be some instance of the object that the API might encounter at runtime.
*bUDT
This is for use for the 3rd function only. This is for cases in which you have user defined types within your DictionaryXML object, and your DictionaryXML object happens to be nested. This lives in the DictionaryXML class as opposed to the DictionaryRuntimeXML class. It is public, but it lives in the base of DictionaryRuntimeXML.
Usage Example
Dictionary<object, object> oObjects = new Dictionary<object, object>();
oObjects.Add("TestObject.MyObject", new TestObject.MyObject());
oObjects.Add("TestObject.TestRecursive", new TestObject.TestRecursive());
oDictionaryXML = new XML_Utilities.DictonaryXML();
strDictionaryXML = oDictionaryXML.Load(Application.StartupPath + "\\Test dictionary.xml");
oDictionaryXML.CreateFromXML(strDictionaryXML, oObjects,true);
Fig 4.2-2
This illustrates how to use the CreateFromXML method. The XML is obtained by loading a file, and the resulting string is passed into the argument. The object oDictionaryXML is then populated based on the data passed into it.
NOTES:
4.3. CreateXML
virtual public string CreateXML(Dictionary<Object, Object> oDictionary) virtual public string CreateXML(Dictionary<Object,Object> oDictionary, Dictionary<object, object> Objects)
This creates an XML document that describes your object at runtime. Your custom object will dynamically discover it's own properties at runtime and obtain information as to the property name, type, and value.
The first declaration is for primitives, and the second is for objects that have other user defined types within them.
oDictionary
This is an array list that you want to pass in, or it can be a type of DictionaryXML class. Array list inherits from the Dictionary class, so you can pass that in since the base type matches the interface argument.
Objects
In the event that you have other user defined or non-primative types of objects nested in your code, you need to pass in a dictionary collection of those types of objects. The XML Object API doesn't know what type of object it will need to create and does not understand ProgID's like COM does. It does understand fully qualified names, and it can use references to certain objects.
When passing in a dictionary object, the name of the object should be a string type, and an instance of an object for reference by the API.
Objects Example
Dictionary<object, object> oDict = new Dictionary<object, object>();
oDict.Add("TestObject.TestRecursive",new TestObject.TestRecursive());
oDict.Add("TestObject.MyObject", new TestObject.MyObject());
oDict.Add("TestObject.TestWidget", new TestObject.TestWidget());
Fig 3.3-1
The code in the above figure illustrates how you should create the dictionary object to pass in. The dictionary should only consist of user defined types that inherit a base class defined in the XML Object API. The first argument should be the fully qualified name as a string, and the value should be some instance of the object that the API might encounter at runtime.
Usage Example
Dictionary<object, object> oObjects = new Dictionary<object, object>();
oObjects.Add("TestObject.MyObject", new TestObject.MyObject());
oObjects.Add("TestObject.TestRecursive", new TestObject.TestRecursive());
strDictionaryXML = oDictionaryXML.CreateXML(oDictionaryXML, oObjects);
oDictionaryXML = null;
Fig 4.3-2
This illustrates how to create the XML from a custom object at runtime. The result is returned to strXML as a string. The string has the XML that explicitly describes the object.
NOTES:
4.4. Load
virtual public string Load(string strFileName)
This loads an XML document, reads the entire file, and returns a string representation of the XML within the document. You must provide the complete file path as well as the file name for strFileName.
If your file is invalid, or doesn't exist, an exception will be thrown. The inner workings of this function uses a file stream reader object.
Usage Example
Dictionary<object, object> oObjects = new Dictionary<object, object>();
oObjects.Add("TestObject.MyObject", new TestObject.MyObject());
oObjects.Add("TestObject.TestRecursive",new TestObject.TestRecursive());
oDictionaryXML = new XML_Utilities.DictonaryXML();
strDictionaryXML = oDictionaryXML.Load(Application.StartupPath + "\\Test dictionary.xml");
oDictionaryXML.CreateFromXML(strDictionaryXML, oObjects,true);
Fig 4.4-1
This illustrates how to load an XML file using the Load function. The file is read, and it returns a string representaiton of the XML descibing a user defined object. The XML can then be used and manipulated to populate the object using the CreateFromXML method.
NOTE:
4.5. SaveXML
virtual public void SaveXML(string strFileName, string strXMLDoc)
virtual public void SaveXML(Type t, Object o,string strFileName)
These methods save XML files that explicitly describe your document. Each overloaded declaration works differently from the next one.
If you have a copy of the XML string that describes your object, you can pass that in along with a file name. The file name should include the complete path of your file as well as the filename itself. This uses a stream writer object when invoked to create the XML file.
NOTES:
The second function makes an internal call to the CreateXML function for an object of type t, from instance o. It then takes that XML, and passes it to the first function to save it to a file. There is no support for a function to serialize XML to a file whose XML is not known, and who's object has other user defined objects within it. Future versions or releases may support this. Therefore, it is suggested to use the first function if possible.
t
T is the type of object you want to populate. You can obtain this by using the GetType method of a given object. GetType returns a System.Type object, which is what this function uses.
Type Example
SaveXML(typeof(MyObject), m_object,strFileName);
SaveXML(m_object.GetType(), m_object,strFileName);
You can use either typeof([Object_Name]) or [Object_Name].GetType() to obtain a System.Type object for use in this method.
Objects
In the event that you have other user defined or non-primitive types of objects nested in your code, you need to pass in a dictionary collection of those types of objects. The XML Object API doesn't know what type of object it will need to create and does not understand ProgID's like COM does. It does understand fully qualified names, and it can use references to certain objects.
When passing in a dictionary object, the name of the object should be a string type, and an instance of an object for reference by the API.
Objects Example
Dictionary<object, object> oDict = new Dictionary<object, object>();
oDict.Add("TestObject.TestRecursive",new TestObject.TestRecursive());
oDict.Add("TestObject.MyObject", new TestObject.MyObject());
oDict.Add("TestObject.TestWidget", new TestObject.TestWidget());
Fig 3.5-1
Usage Example
Dictionary<object, object> oObjects = new Dictionary<object, object>();
oObjects.Add("TestObject.MyObject", new TestObject.MyObject());
oObjects.Add("TestObject.TestRecursive",new TestObject.TestRecursive());
oDictionaryXML = new XML_Utilities.DictonaryXML();
strDictionaryXML = oDictionaryXML.Load(Application.StartupPath + "\\Test dictionary.xml");
oDictionaryXML.CreateFromXML(strDictionaryXML, oObjects,true);
oDictionaryXML.SaveXML(Application.StartupPath + "\\Test Test dictionary from file.xml", oDictionaryXML.CreateXML(oDictionaryXML, oObjects));
//Save the file as XML
oTest.SaveXML(Application.StartupPath + "\\Test dictionary.xml", strDictionaryXML);
oDictionaryXML = null;
Fig 4.5-2
The above illustration demonstrates how to create an XML document using the CreateXML method. From there, you pass that string into the SaveXML method. The complete path is determined dynamically at runtime and concatenated with the actual file name.
I actually have this in an MS Word document.
Here is the reason I wrote this to begin with, and then I realized the potential this had that I didn't at the time.
I know Sun has their agreements in place to support SOAP. I don't care for anything non-MS related. However, there is this ugly thing called reality. The entire world isn't going to just flip a switch to MS stuff. However, they need to work together, and SOAP is a great starting point for that.
So....I figured, it would be nice if there was a way to use OOP and SOAP. Well, any idiot (well almost anyone that is with some know how) can describe any object instance and it's data in a string like an XML document. The thing is, when you get past the end point, you have a load of extra work.
So....I figured, there has to be a way to pass an XML document as a string such that at the other side of the endpoint of a web service, some framework can say, this document describes this particular object. So let's create an instance, and we know from what's here there are n possibilities. Let's validate this schema against what interfaces are in the current assembly on the fly, and if it washes, cool. Let's populate it with an overloaded construct that accepts this XML document, and then everything is object oriented.
The other thing I thought about was in the event that you have a serviced component and you're limited to a strict type or primative, I remember a senior developer who said put in an XML string. Then you can just do what you need to before you start the actual transaction. So that thinking is what inspired me years ago.
The technology to support it wasn't there till VS 2005 came out, and C# was the only thing that would support dynamic interface discovery that I needed to pull this off to validate it against the XML document coming in. So that's how it started, and I added to it.
So my vision was this. Assume we have some IBM (cough) dinosaur running some SOAP endpoint. I have my MS stuff here. I can take care of the maintenance part on the MS side of the endpoint. If you could have some java thing to do the same thing on the other end, you could basically say, here is an object. Convert it to an XML document that's formated and well described so that the other side can parse it, validate it, and accept it as if it were all part of one system.
The first time I ever used it for a web application like that was for an n-tiered application for my final project. For each tier, I implemented a SOAP endpoint. So if I had one thing in Honk Kong, another in LA, and something else in who knows where, I could integrate them all and essentially pass objects across the globe as metadata. On the other side of the endpoint, the entire thing is dynamic as if everything was traditional OOP.
Long story short, on my laptop, running SQL and everything else on a single machine, I benchmarked 1800 messages a minute across a single domain (support for many) with an MTA service running and interacting with SQL to archive the mail messages across 10 test accounts. I used this API to do the conversion so that the maintenance time would be nothing.
I tried to send the document to various people. That, and $4 will get you a cup of coffee at Starbucks. On some bigger stuff, you could save some serious engineering resources up front and in the long term by integrating different platforms with this sort of thinking.
However, that just doesn't seem to phase anyone at all for some reason when I put it all strictly in writing. (((shrugs)))
-joe
Well, you have my interest up now. I don't get much time to do much .NET coding lately, but when I do, I'm gonna try playing around with this.
Olympus
Single & Not Looking
Cool, another thing we have in common, I used to be a long hair too,
. Maybe if ya move out to San Fran or somewhere else in Silicon Valley, where they love that kinda thing. Plus, that's where the big bucks are I hear. ;D
Do you have this in an organized .pdf, or something similar? I'm actually interested in taking a closer look.