Using the XML Event Loader API

If you want to submit XML data to a Notification Services application, use the XML event loader API. Using this API, you produce a batch of notifications from a single XML document.

The XML event loader API has one class: EventLoader.

Creating and Initializing the EventLoader class

You can create and initialize an EventLoader object by using the parameterized constructor to pass in an NSApplication object that represents the desired Notification Services application, the name of the event provider, the name of the event class, and the name of the SQL-annotated XML schema file that maps the data from the XML document structure to the event class structure.

For more information about authoring an SQL-annotated XML schema file, see Authoring and Using Custom Schemas Backgrounder in the Microsoft MSDN Library.

Submitting Event Data

After you create and initialize an EventLoader object, use the LoadXml method to write an event batch of one or more events from an XML data source to the Notification Services application database.

Example

This example uses the following namespaces:

public bool Run()
{
    // These variables would normally be defined for
    // the class. They would be set based on the values
    // provided by the args argument of the Initialize method.
    string instanceName = "MyInstanceName";
    string applicationName = "MyApplicationName";
    string eventClassName = "MyEventClassName";
    string eventProviderName = "MyEventProviderName";
    string eventSchema = "MyEventSchemaPathAndName";
    string xmlDoc = "MyXMLDocPathAndName";

    bool returnValue = true;
    DateTime currentTime = DateTime.Now;

    try
    {
        // Get the Notification Services instance.
        NSInstance testInstance = new NSInstance(instanceName);

        // Get the Notification Services application.
        NSApplication testApplication =
            new NSApplication(testInstance, applicationName);

        // Create the EventLoader object.
        EventLoader testEventLoader =
            new EventLoader(testApplication, eventProviderName,
            eventClassName, eventSchema);

        // Write the event records from the XML data 
        // source to the application database.
        int eventsSubmitted = testEventLoader.LoadXml(xmlDoc);
    }
    catch(Exception e)
    {
        //Add code to handle errors here.
    }

    return returnValue;
}

See Also

Other Resources

Developing a Custom Event Provider
Defining Event Providers

Help and Information

Getting SQL Server 2005 Assistance