XmlReaderDecoratorExtensions Class
Definition
- Assemblies
- Cuemon.Xml.dll
Extension methods for the XmlReader class hidden behind the IDecorator<T> interface.
public static class XmlReaderDecoratorExtensions
- Inheritance
-
XmlReaderDecoratorExtensions
Examples
The following example demonstrates how to move to the first XML element, chunk a document, and build a hierarchy from an
using System;
using System.Collections.Generic;
using System.IO;
using System.Xml;
using Cuemon;
using Cuemon.Xml;
namespace MyApp.Examples;
public static class XmlReaderDecoratorExtensionsExample
{
public static void Demonstrate()
{
const string xml = "<items><item id=\"1\"/><item id=\"2\"/><item id=\"3\"/></items>";
using var reader = XmlReader.Create(new StringReader(xml));
var hasElement = Decorator.Enclose(reader).MoveToFirstElement();
Console.WriteLine(hasElement);
Console.WriteLine(reader.LocalName);
using var chunkReader = XmlReader.Create(new StringReader(xml));
var chunks = new List<XmlReader>(Decorator.Enclose(chunkReader).Chunk(size: 2));
Console.WriteLine(chunks.Count);
using var hierarchyReader = XmlReader.Create(new StringReader(xml));
var hierarchy = Decorator.Enclose(hierarchyReader).ToHierarchy();
Console.WriteLine(hierarchy.Instance.Name);
}
}
Methods
| Name | Description |
|---|---|
| Chunk(IDecorator<XmlReader>, int, Action<XmlWriterSettings>) | Creates and returns a sequence of chunked XmlReader instances from the enclosed XmlReader of the specified |
| MoveToFirstElement(IDecorator<XmlReader>) | Moves the enclosed XmlReader of the specified |
| ToHierarchy(IDecorator<XmlReader>) | Converts the XML hierarchy of the enclosed XmlReader of the specified |
See Also
IDecorator<T>
Decorator<T>