Table of Contents

XPathDocumentFactory Class

Definition

Namespace
Cuemon.Xml.XPath
Assemblies
Cuemon.Xml.dll
Source
src/Cuemon.Xml/XPath/XPathDocumentFactory.cs

Provides access to factory methods for creating and configuring IXPathNavigable instances.

public static class XPathDocumentFactory
Inheritance
XPathDocumentFactory

Examples

The following example creates an XPathDocument from an XML string using XPathDocumentFactory, then queries it with an XPath expression to retrieve the text content of an <item> element. The resulting value "Hello" is written to the console.

using System;
using System.Xml.XPath;
using Cuemon.Xml.XPath;

namespace Cuemon.Xml.XPath;

public class XPathDocumentFactoryExample
{
    public void Demonstrate()
    {
        var xml = "<root><item id=\"1\">Hello</item></root>";
        var doc = XPathDocumentFactory.CreateDocument(xml);

        var navigator = doc.CreateNavigator();
        var value = navigator.SelectSingleNode("//item/text()")?.Value;
        Console.WriteLine($"XPath result: {value}");
    }
}

Methods

Name Description
CreateDocument(Stream, bool)

Creates and returns an instance of XPathDocument from the specified stream.

CreateDocument(string)

Creates and returns an instance of XPathDocument from the specified value.

CreateDocument(string, Encoding)

Creates and returns an instance of XPathDocument from the specified value.

CreateDocument(Uri)

Creates and returns an instance of XPathDocument from the specified uriLocation.

CreateDocument(XmlReader)

Creates and returns an instance of XPathDocument from the specified reader.