Custom XML Providers must implement the interface ICustomXmlProvider located in the namespace Composite.Cms.Pub.Interfaces. ICustomXmlProvider is a fairly simple interface to implement which you can see from its definition:
using System.Collections.Generic;
using System.Xml;
namespace Composite.Cms.Pub.Interfaces
{
public interface ICustomXmlProvider
{
void WriteXml(Dictionary<string, string> parameters, XmlWriter xmlTarget);
}
}
A Custom XML Provider is expected to implement one function, WriteXml, which gets a string based dictionary object (parameters, from the XSLT developer) and an XmlWriter object (xmlTarget, where you emit your XML to the XSLT developer).
Here is a “Hello World” sample of a C# class implementing ICustomXmlProvider:
using System.Xml;
using System.Collections.Generic;
using Composite.Cms.Pub.Interfaces;
public class HelloWorldXmlProvider : ICustomXmlProvider
{
public void WriteXml(Dictionary<string, string> parameters, XmlWriter xmlTarget)
{
// Start the document...
xmlTarget.WriteStartDocument();
// Write XML root element start
xmlTarget.WriteStartElement("Greeting");
// Write string
xmlTarget.WriteString("Hello World");
// End the root element
xmlTarget.WriteEndElement();
// End the document
xmlTarget.WriteEndDocument();
}
}
This code will emit the following XML:
<Greeting>
Hello World
</Greeting>