| ILOG Rules for .NET User Guides > Rule Studio > Executing Rules > Using XML Data |
Using XML Data |
PREVIOUS NEXT |
You can generate .NET classes based on XML data and include them in a business object model. This enables you to write business rules that can be executed against data stored as XML.
In order to run rules against XML data, ILOG Rules for .NET uses a mapping between XML Schema and CLR type systems.
To generate the .NET classes you use the XmlSchemaCodeGenerator tool included with ILOG Rule Studio for .NET. Classes can be automatically generated from an XML Schema by setting XmlSchemaCodeGenerator as the custom tool.
The mechanism used by the XmlSchemaCodeGenerator tool is similar to the one provided by the XML Schema Definition tool in the .NET Framework. The advantage of using the XmlSchemaCodeGenerator tool is that you can write an XML Schema within Visual Studio .NET, and incrementally update your model as the Schema evolves without leaving the development environment.
*.xsd) file that defines the data.
XmlSchemaCodeGenerator. The XmlSchemaCodeGenerator tool generates .NET classes every time you save the XML Schema.
The source code is automatically generated each time you save changes to the XML Schema.
The generated classes are designed to work with the XML Serialization classes of the .NET Framework. So, to instantiate and use the XML objects in an application that embeds the ILOG Rule Engine for .NET, you map the XML data stream to a set of objects, add these objects to the working memory, run the business rules, and, optionally, serialize the result objects back into an XML stream.
The following sample shows how to use the XmlSerializer class:
[C#]
// Construct an instance of XmlSerializer // with the type of object being [de]serialized. XmlSerializer serializer = new XmlSerializer(typeof(MyClass)); // Create an XML reader // (a generic stream can be used as well) XmlReader reader = new XmlTextReader(“input.xml”); // Deserialize MyClass myObject = (MyClass) serializer.Deserialize(reader); // Add myObject into the working memory // (...) // Create an XML writer // (a generic stream can be used as well) XmlWriter writer = new XmlTextWriter(“output.xml”); // Serialize the result. serializer.Serialize(writer, myObject);
[Visual Basic]
` Construct an instance of XmlSerializer
` with the type of object being [de]serialized.
Dim serializer as XmlSerializer
serializer = new XmlSerializer(GetType(MyClass))
` Create an XML reader
` (a generic stream can be used as well)
Dim reader as XmlReader
reader =
new XmlTextReader("input.xml")
` Deserialize
Dim myObject as MyClass
myObject = CType(serializer.Deserialize(reader), MyClass)
` Add myObject into the working memory
` (...)
` Create an XML writer
` (a generic stream can be used as well)
Dim writer as XmlWriter
writer = new XmlTextWriter("output.xml")
` Serialize the result.
serializer.Serialize(writer, myObject)
Retrieving Data and Events From the Engine | Retrieving Data and Events From the Engine | Setting an Exception Handler on the Engine Execution | XML Binding Sample
| Copyright © 1987-2008 ILOG S.A. All rights reserved. Legal terms. Documentation homepage. | PREVIOUS NEXT |