The DOMXPath class

- « DOMText::splitText

- DOMXPath::__construct »

- PHP Manual
- DOM
- The DOMXPath class

# The DOMXPath class

(PHP 5, PHP 7, PHP 8)

## Introduction

Supports XPath 1.0

## Class synopsis

class DOMXPath {
/* Properties */
public readonly DOMDocument $document;
public bool $registerNodeNamespaces;
/* Methods */
public __construct(DOMDocument `$document`, bool `$registerNodeNS` = `true`)
public evaluate(string `$expression`, ?DOMNode `$contextNode` = `null`, bool `$registerNodeNS` = `true`): mixed
public query(string `$expression`, ?DOMNode `$contextNode` = `null`, bool `$registerNodeNS` = `true`): mixed
public registerNamespace(string `$prefix`, string `$namespace`): bool
public registerPhpFunctions(string|array|null `$restrict` = `null`): void
}

## Properties

document

registerNodeNamespaces

  When set to `true`, namespaces in the node are registered.

## Changelog

Version | Description
--- | ---
8.0.0 | The registerNodeNamespaces property has been added.

## Table of Contents

- DOMXPath::__construct — Creates a new DOMXPath object
- DOMXPath::evaluate — Evaluates the given XPath expression and returns a typed result if possible
- DOMXPath::query — Evaluates the given XPath expression
- DOMXPath::registerNamespace — Registers the namespace with the DOMXPath object
- DOMXPath::registerPhpFunctions — Register PHP functions as XPath functions