Table of Contents

Class XmlDataProvider

Namespace
combit.Reporting.DataProviders
Assembly
combit.ListLabel31.CrossPlatform.dll

Provides an XML-based data provider implementation that parses XML documents and exposes their data as tables and relations.

[Serializable]
public sealed class XmlDataProvider : IDataProvider, ICanHandleUsedIdentifiers, ISerializable, IFileList
Inheritance
XmlDataProvider
Implements
Inherited Members

Examples

The following example demonstrates how to use the XmlDataProvider to export a report to PDF:

// Example 1: Load XML from a file
XmlDataProvider provider = new XmlDataProvider(@"C:\Data\customers.xml");

// Optional: Configure parsing behavior
provider.FlattenStructure = true;
provider.ParseFirstElementOnly = true; // Better performance for consistent XML

// Create a ListLabel reporting engine instance and assign the provider as the data source.
using ListLabel listLabel = new ListLabel();
listLabel.DataSource = provider;

// Configure export settings to generate a PDF.
ExportConfiguration exportConfiguration = new ExportConfiguration(LlExportTarget.Pdf, exportFilePath, projectFilePath);
exportConfiguration.ShowResult = true;

// Export the report to PDF.
listLabel.Export(exportConfiguration);

// Example 2: Load XML from an XmlDocument
XmlDocument xmlDoc = new XmlDocument();
xmlDoc.Load(@"C:\Data\orders.xml");
XmlDataProvider docProvider = new XmlDataProvider(xmlDoc);

// Example 3: Handle XML with namespaces
XmlNamespaceManager nsManager = new XmlNamespaceManager(new NameTable());
nsManager.AddNamespace("ns", "http://example.com/schema");

XmlDataProvider nsProvider = new XmlDataProvider(@"C:\Data\data.xml");
nsProvider.AutoResolveNamespacesMode = AutoResolveNamespacesMode.SearchEverywhere;

// Example 4: Configure structure flattening and empty node handling
XmlDataProvider flatProvider = new XmlDataProvider(@"C:\Data\complex.xml");
flatProvider.FlattenStructure = true;
flatProvider.FlattenNodesWithNoAttributes = true;
flatProvider.RegisterEmptyNodesAsColumnsWhenFlattening = true; // Include empty tags

// Example 5: Custom value field name
XmlDataProvider customProvider = new XmlDataProvider(@"C:\Data\products.xml");
customProvider.ValueFieldName = "TextContent"; // Instead of default "value"

// Example 6: Handle custom node types with events
XmlDataProvider eventProvider = new XmlDataProvider(@"C:\Data\mixed.xml");

eventProvider.GetNodeType += (sender, args) =>
{
    // Force specific nodes to be flattened or table
    if (args.Node.Name == "Address")
    {
        args.NodeType = NodeType.Flat;
    }
};

eventProvider.PreParseXPathNavigator += (sender, args) =>
{
    // Custom parsing for specific nodes
    if (args.Navigator.Name == "CustomDate")
    {
        args.ParsedType = typeof(DateTime);
        args.ParsedContent = DateTime.Parse(args.Navigator.Value);
        args.SkipDefaultProcessing = true;
    }
};

// Example 7: Load from URL
XmlDataProvider urlProvider = new XmlDataProvider(
    "https://example.com/api/data.xml");

// Example 8: Dynamic XML source with parameters
XmlDataProvider paramProvider = new XmlDataProvider(@"C:\Data\report1.xml");
// The URI property supports parameter binding
// When the parameter changes, the XML source automatically switches

Remarks

The XmlDataProvider supports parsing of XML documents using XPath and exposes the underlying data structure to reporting engines. It supports both flat and hierarchical structures and provides options to flatten the structure and register empty nodes as columns.

Constructors

XmlDataProvider()

Initializes a new instance of the XmlDataProvider class.

public XmlDataProvider()

XmlDataProvider(string, ProvideXPathDocument?)

Initializes a new instance of the XmlDataProvider class with the specified URI.

public XmlDataProvider(string uri, XmlDataProvider.ProvideXPathDocument? provideXPathDocument = null)

Parameters

uri string

The URI of the XML document.

provideXPathDocument XmlDataProvider.ProvideXPathDocument

An optional callback to provide an XPath document.

XmlDataProvider(IXPathNavigable)

Initializes a new instance of the XmlDataProvider class with the specified document.

public XmlDataProvider(IXPathNavigable document)

Parameters

document IXPathNavigable

An object that implements IXPathNavigable representing the XML document.

Properties

AutoResolveNamespacesMode

Gets or sets the mode used to automatically resolve XML namespaces.

public AutoResolveNamespacesMode AutoResolveNamespacesMode { get; set; }

Property Value

AutoResolveNamespacesMode

Document

Gets or sets the XML document to be parsed.

public IXPathNavigable Document { get; set; }

Property Value

IXPathNavigable

FlattenNodesWithNoAttributes

Gets or sets a value indicating whether nodes with no attributes should be flattened.

public bool FlattenNodesWithNoAttributes { get; set; }

Property Value

bool

FlattenStructure

Gets or sets a value indicating whether the XML structure should be flattened.

public bool FlattenStructure { get; set; }

Property Value

bool

ParseFirstElementOnly

Gets or sets a value indicating whether only the first element in the XML file should be parsed. When set to true, only the first element is parsed which may boost performance.

public bool ParseFirstElementOnly { get; set; }

Property Value

bool

RegisterEmptyNodesAsColumnsWhenFlattening

When FlattenStructure is enabled, this property determines whether empty XML nodes are registered as columns. If set to true, empty XML nodes will be registered as columns even when flattening is enabled.

public bool RegisterEmptyNodesAsColumnsWhenFlattening { get; set; }

Property Value

bool

Uri

Gets or sets the URI of the XML document to be parsed. Setting this property resets the current document and marks all tables as volatile.

public string Uri { get; set; }

Property Value

string

ValueFieldName

Gets or sets the field name to be used for the value of XML elements that have attributes. For example, in <item unit="Dollar">17</item>, the field name for the content "17" will be value.

public string ValueFieldName { get; set; }

Property Value

string

Events

GetNodeType

Occurs when determining the node type during XML parsing. Subscribers can override the default node type determination.

public event EventHandler<GetNodeTypeEventArgs> GetNodeType

Event Type

EventHandler<GetNodeTypeEventArgs>

PreParseXPathNavigator

Occurs before parsing an XPathNavigator. This event allows custom handling or overriding of the parsing process.

public event EventHandler<PreParseXPathNavigatorEventArgs> PreParseXPathNavigator

Event Type

EventHandler<PreParseXPathNavigatorEventArgs>