<?xml version="1.0" encoding="UTF-8"?>
<xao-docs>
  <site name="XaoDocs" product="Xao" version="1.0.0-dev" homepage="https://xao.ndx.au" repo="https://github.com/ndx-au/Xao" examples-repo="https://github.com/ndx-au/xao-example-apps"/>
  <request slug="core-api" theme="atlas" path="/xml/core-api" xml-url="/xml/core-api"/>
  <themes>
    <theme id="atlas" name="Atlas" tagline="Three-column reference desk with persistent sidebar and sticky page outline" audience="API and framework developers browsing across sections" structure="3-column grid: left navigation sidebar, center article, right on-this-page outline" css="/assets/atlas.css" active="true"/>
    <theme id="folio" name="Folio" tagline="Editorial journal spread with XPath-grouped numbered chapters and collapsible library" audience="Architects and evaluators reading long-form conceptual chapters" structure="Editorial cover header, collapsible library drawer, and sibling-grouped numbered chapter sections" css="/assets/folio.css" active="false"/>
    <theme id="console" name="Console" tagline="Operations dashboard with telemetry strip and collapsible H2 module accordions" audience="SREs, operators, and runtime engineers scanning sections quickly" structure="Command header, telemetry bar, compact nav rail, and expandable &lt;details&gt; module accordions" css="/assets/console.css" active="false"/>
    <theme id="reader" name="Reader (A11y)" tagline="WCAG AAA single-column linear reader with upfront summary, numbered TOC, and zero JS" audience="Screen reader users, keyboard-only navigation, and low-vision / cognitive accessibility" structure="Multi-landmark skip links, upfront document summary, inline numbered TOC, figure-wrapped code blocks, directory after article, zero JS" css="/assets/reader.css" active="false"/>
    <theme id="handbook" name="Handbook" tagline="Single-column print-ready technical specification sheet with metadata ledger" audience="Technical reviewers, auditors, and print/PDF export workflows" structure="Single-column specification document with &lt;dl&gt; metadata ledger, numbered outline, and print stylesheet" css="/assets/handbook.css" active="false"/>
  </themes>
  <navigation>
    <section name="Start Here">
      <item slug="index" title="Xao Documentation" description="XML Application Objects for PHP 8 and PHC — zero-dependency XML content aggregation and XSLT 3.0 presentation." order="1" active="false"/>
      <item slug="getting-started" title="Getting Started" description="Set up PHC, autoload Xao with zero Composer packages, transform your first DomDoc with XSLT 3.0, and run phc serve." order="2" active="false"/>
    </section>
    <section name="Core Concepts">
      <item slug="architecture" title="Architecture &amp; XML Aggregation" description="How Xao builds a unified XML conglomeration document from databases, Markdown, and domain objects before delegating presentation to XSLT 3.0." order="3" active="false"/>
      <item slug="xslt-themes" title="XSLT 3.0 Themes vs CSS Skins" description="Why XSLT themes are structurally and semantically richer than CSS-only themes — including accessibility-first DOM transformations." order="4" active="false"/>
    </section>
    <section name="Framework Reference">
      <item slug="core-api" title="Core API Reference" description="Reference for Xao\\Runtime, Xao\\XaoRoot, Xao\\DomDoc, Xao\\DomFactory, Xao\\AppDoc, Xao\\Http\\Response, and Xao\\Exceptions." order="5" active="true"/>
      <item slug="database-aggregation" title="Database Aggregation (DbToXml)" description="Convert PDO queries, PDOStatement results, and PHP iterables directly into structured DomDoc XML fragments under PHC." order="6" active="false"/>
      <item slug="markdown-aggregation" title="Markdown Aggregation" description="Convert CommonMark and GFM into CommonMark XML 1.0 natively in PHC via comrak and graft it into Xao DomDoc trees." order="7" active="false"/>
      <item slug="xslt-drivers" title="XSLT 3.0 Drivers" description="Pluggable XsltDriverInterface strategies: PhcNativeXsltDriver (default in-process), SaxonHttpDriver (HTTP/distributed), and ClientSideXslDriver." order="8" active="false"/>
    </section>
    <section name="Operations &amp; Runtime">
      <item slug="phc-runtime" title="PHC Runtime &amp; Compatibility" description="Running Xao on PHC in isolate and worker modes, sandbox defaults, worker-safe autoloading, and P00–P05 compatibility findings." order="9" active="false"/>
      <item slug="security" title="Security Model" description="XXE rejection, realpath containment, strict slug allowlists, CSRF guards, gated debug output, and PHC sandbox enforcement." order="10" active="false"/>
    </section>
    <section name="Examples &amp; Design">
      <item slug="reference-apps" title="Reference Applications" description="Comparing Xao's built-in SQLite PDO catalog reference app with XaoDocs, the flat-file Markdown multi-theme CMS." order="11" active="false"/>
      <item slug="adr-0001-phc-xee-xslt" title="ADR 0001 &amp; Roadmap" description="Architecture Decision Record for pure-Rust xee-xslt in PHC plus the Xao v1.0.0 milestone and phase roadmap (M0–M3, P00–P06)." order="12" active="false"/>
    </section>
  </navigation>
  <page slug="core-api" title="Core API Reference" description="Reference for Xao\\Runtime, Xao\\XaoRoot, Xao\\DomDoc, Xao\\DomFactory, Xao\\AppDoc, Xao\\Http\\Response, and Xao\\Exceptions." section="Framework Reference" audience="PHP 8 developers building on Xao" status="stable" words="666" reading-minutes="4" source-file="content/core-api.md">
    <tags>
      <tag>api</tag>
      <tag>domdoc</tag>
      <tag>appdoc</tag>
      <tag>exceptions</tag>
    </tags>
    <neighbors>
      <prev slug="xslt-themes" title="XSLT 3.0 Themes vs CSS Skins"/>
      <next slug="database-aggregation" title="Database Aggregation (DbToXml)"/>
    </neighbors>
    <body>
      <document xmlns="http://commonmark.org/xml/1.0">
        <heading level="1">
          <text xml:space="preserve">Core API Reference</text>
        </heading>
        <paragraph>
          <text xml:space="preserve">All framework classes under </text>
          <code xml:space="preserve">src/</code>
          <text xml:space="preserve"> declare </text>
          <code xml:space="preserve">strict_types=1</code>
          <text xml:space="preserve">, require zero Composer packages, and pass </text>
          <code xml:space="preserve">phc check</code>
          <text xml:space="preserve"> plus PHP 8.4 parity tests.</text>
        </paragraph>
        <heading level="2">
          <code xml:space="preserve">Xao\Runtime</code>
        </heading>
        <paragraph>
          <text xml:space="preserve">Source: </text>
          <code xml:space="preserve">src/Runtime.php</code>
        </paragraph>
        <list type="bullet" tight="true">
          <item>
            <paragraph>
              <code xml:space="preserve">public const VERSION = '1.0.0-dev'</code>
              <text xml:space="preserve"> (targeting </text>
              <code xml:space="preserve">v1.0.0</code>
              <text xml:space="preserve">)</text>
            </paragraph>
          </item>
          <item>
            <paragraph>
              <code xml:space="preserve">public const NAME = 'Xao'</code>
            </paragraph>
          </item>
          <item>
            <paragraph>
              <code xml:space="preserve">public static function health(): array</code>
              <text xml:space="preserve"> — returns </text>
              <code xml:space="preserve">['framework' =&gt; string, 'version' =&gt; string, 'status' =&gt; string]</code>
              <text xml:space="preserve">.</text>
            </paragraph>
          </item>
        </list>
        <heading level="2">
          <code xml:space="preserve">Xao\XaoRoot</code>
        </heading>
        <paragraph>
          <text xml:space="preserve">Source: </text>
          <code xml:space="preserve">src/XaoRoot.php</code>
        </paragraph>
        <paragraph>
          <text xml:space="preserve">Base class providing structured, inspectable error tracking without silent failures:</text>
        </paragraph>
        <list type="bullet" tight="true">
          <item>
            <paragraph>
              <code xml:space="preserve">addError(string $message, string $errorCode = 'XAO_ERROR', array $context = []): void</code>
            </paragraph>
          </item>
          <item>
            <paragraph>
              <code xml:space="preserve">addException(XaoException $exception): void</code>
            </paragraph>
          </item>
          <item>
            <paragraph>
              <code xml:space="preserve">hasErrors(): bool</code>
            </paragraph>
          </item>
          <item>
            <paragraph>
              <code xml:space="preserve">getErrors(): array</code>
            </paragraph>
          </item>
          <item>
            <paragraph>
              <code xml:space="preserve">getLastError(): ?array</code>
            </paragraph>
          </item>
          <item>
            <paragraph>
              <code xml:space="preserve">clearErrors(): void</code>
            </paragraph>
          </item>
          <item>
            <paragraph>
              <code xml:space="preserve">throwError(string $message, string $errorCode = 'XAO_ERROR', array $context = []): void</code>
            </paragraph>
          </item>
        </list>
        <heading level="2">
          <code xml:space="preserve">Xao\DomDoc</code>
          <text xml:space="preserve"> (extends </text>
          <code xml:space="preserve">XaoRoot</code>
          <text xml:space="preserve">)</text>
        </heading>
        <paragraph>
          <text xml:space="preserve">Source: </text>
          <code xml:space="preserve">src/DomDoc.php</code>
        </paragraph>
        <paragraph>
          <text xml:space="preserve">Core XML Application Object wrapping </text>
          <code xml:space="preserve">DOMDocument</code>
          <text xml:space="preserve"> and </text>
          <code xml:space="preserve">DOMXPath</code>
          <text xml:space="preserve">:</text>
        </paragraph>
        <list type="bullet" tight="true">
          <item>
            <paragraph>
              <code xml:space="preserve">__construct(string|DOMDocument $root = 'root', string $version = '1.0', string $encoding = 'UTF-8')</code>
            </paragraph>
          </item>
          <item>
            <paragraph>
              <code xml:space="preserve">getDocument(): DOMDocument</code>
              <text xml:space="preserve"> / </text>
              <code xml:space="preserve">getRoot(): DOMNode</code>
            </paragraph>
          </item>
          <item>
            <paragraph>
              <code xml:space="preserve">toXml(bool $formatOutput = false): string</code>
              <text xml:space="preserve"> / </text>
              <code xml:space="preserve">xmlGetDoc(bool $formatOutput = false): string</code>
            </paragraph>
          </item>
          <item>
            <paragraph>
              <code xml:space="preserve">ndAppendToNode(DOMNode $target, string $name, ?string $value = null, array $attributes = []): DOMElement</code>
            </paragraph>
          </item>
          <item>
            <paragraph>
              <code xml:space="preserve">ndAppendToRoot(string $name, ?string $value = null, array $attributes = []): DOMElement</code>
            </paragraph>
          </item>
          <item>
            <paragraph>
              <code xml:space="preserve">ndConsumeNode(DOMNode $node, ?DOMNode $target = null): DOMNode</code>
            </paragraph>
          </item>
          <item>
            <paragraph>
              <code xml:space="preserve">ndConsumeDoc(DomDoc $source, ?DOMNode $target = null): DOMElement</code>
            </paragraph>
          </item>
          <item>
            <paragraph>
              <code xml:space="preserve">ndConsumeXml(string $xml, ?DOMNode $target = null): DOMElement</code>
            </paragraph>
          </item>
          <item>
            <paragraph>
              <code xml:space="preserve">ndConsumeFile(string $filePath, ?DOMNode $target = null, ?string $baseDir = null): DOMElement</code>
            </paragraph>
          </item>
          <item>
            <paragraph>
              <code xml:space="preserve">ndAppendToNodeNS(DOMNode $parent, string $namespaceUri, string $qualifiedName, ?string $text = null, array $attributes = []): DOMElement</code>
            </paragraph>
          </item>
          <item>
            <paragraph>
              <code xml:space="preserve">ndAppendToRootNS(string $namespaceUri, string $qualifiedName, ?string $text = null, array $attributes = []): DOMElement</code>
            </paragraph>
          </item>
          <item>
            <paragraph>
              <code xml:space="preserve">arrGetElementsByTagNameNS(string $namespaceUri, string $localName): array</code>
            </paragraph>
          </item>
          <item>
            <paragraph>
              <code xml:space="preserve">ndImportNode(DOMNode $node, bool $deep = true, ?DOMNode $target = null): DOMNode</code>
            </paragraph>
          </item>
          <item>
            <paragraph>
              <code xml:space="preserve">toCanonicalXml(bool $exclusive = false, bool $withComments = false): string</code>
            </paragraph>
          </item>
          <item>
            <paragraph>
              <code xml:space="preserve">xpath(array $namespaces = []): DOMXPath</code>
            </paragraph>
          </item>
          <item>
            <paragraph>
              <code xml:space="preserve">arrGetByXpath(string $query, ?DOMNode $contextNode = null, array $namespaces = []): array</code>
            </paragraph>
          </item>
          <item>
            <paragraph>
              <code xml:space="preserve">evaluateXpath(string $expression, ?DOMNode $contextNode = null, array $namespaces = []): mixed</code>
            </paragraph>
          </item>
          <item>
            <paragraph>
              <code xml:space="preserve">ndGetOneByXpath(string $query, ?DOMNode $contextNode = null, array $namespaces = []): ?DOMNode</code>
            </paragraph>
          </item>
          <item>
            <paragraph>
              <code xml:space="preserve">ndAppendError(string $message, string $errorCode = 'XAO_ERROR', array $context = [], ?DOMNode $target = null): DOMElement</code>
            </paragraph>
          </item>
          <item>
            <paragraph>
              <code xml:space="preserve">ndAppendException(XaoException $exception, ?DOMNode $target = null): DOMElement</code>
            </paragraph>
          </item>
          <item>
            <paragraph>
              <code xml:space="preserve">static parseXmlToDomDocument(string $xml): DOMDocument</code>
              <text xml:space="preserve"> — rejects empty XML and </text>
              <code xml:space="preserve">&lt;!DOCTYPE</code>
              <text xml:space="preserve"> / </text>
              <code xml:space="preserve">&lt;!ENTITY</code>
              <text xml:space="preserve"> declarations.</text>
            </paragraph>
          </item>
          <item>
            <paragraph>
              <code xml:space="preserve">static resolveSafeFilePath(string $filePath, ?string $baseDir = null): string</code>
              <text xml:space="preserve"> — enforces </text>
              <code xml:space="preserve">realpath()</code>
              <text xml:space="preserve"> base-directory containment.</text>
            </paragraph>
          </item>
        </list>
        <heading level="3">
          <text xml:space="preserve">Content Callbacks</text>
        </heading>
        <paragraph>
          <text xml:space="preserve">Register PHP callables on the document being assembled. Use </text>
          <code xml:space="preserve">onElement(string $localName, callable $handler, string $namespaceUri = '')</code>
          <text xml:space="preserve"> for an element name and </text>
          <code xml:space="preserve">onXPath(string $selector, callable $handler, array $namespaces = [])</code>
          <text xml:space="preserve"> for a node selection. Namespace matching uses the URI, so the author can choose a different prefix in each imported fragment.</text>
        </paragraph>
        <paragraph>
          <text xml:space="preserve">Call </text>
          <code xml:space="preserve">processContentCallbacks()</code>
          <text xml:space="preserve"> after importing the fragments and before the XSLT transformation. It selects all matches first, then invokes each handler with one matched node in registration order. Elements added by a handler become eligible on a subsequent explicit pass. Select the owning element for portable edits, since PHC can store leaf text directly on its element.</text>
        </paragraph>
        <heading level="2">
          <code xml:space="preserve">Xao\DomFactory</code>
        </heading>
        <paragraph>
          <text xml:space="preserve">Source: </text>
          <code xml:space="preserve">src/DomFactory.php</code>
        </paragraph>
        <list type="bullet" tight="true">
          <item>
            <paragraph>
              <code xml:space="preserve">static fromXml(string $xml): DomDoc</code>
            </paragraph>
          </item>
          <item>
            <paragraph>
              <code xml:space="preserve">static fromFile(string $filePath, ?string $baseDir = null): DomDoc</code>
            </paragraph>
          </item>
          <item>
            <paragraph>
              <code xml:space="preserve">static fromRoot(string $rootTag, string $version = '1.0', string $encoding = 'UTF-8'): DomDoc</code>
            </paragraph>
          </item>
        </list>
        <heading level="2">
          <code xml:space="preserve">Xao\AppDoc</code>
        </heading>
        <paragraph>
          <text xml:space="preserve">Source: </text>
          <code xml:space="preserve">src/AppDoc.php</code>
        </paragraph>
        <paragraph>
          <text xml:space="preserve">Stateless, worker-mode-safe front controller:</text>
        </paragraph>
        <list type="bullet" tight="true">
          <item>
            <paragraph>
              <code xml:space="preserve">__construct(Transformer $transformer, bool $debug = false)</code>
            </paragraph>
          </item>
          <item>
            <paragraph>
              <code xml:space="preserve">isDebugEnabled(): bool</code>
            </paragraph>
          </item>
          <item>
            <paragraph>
              <code xml:space="preserve">registerRoute(string $path, callable $handler, string $stylesheet, string $contentType = 'text/html; charset=utf-8'): void</code>
            </paragraph>
          </item>
          <item>
            <paragraph>
              <code xml:space="preserve">handle(string $rawPath, array $query = []): Response</code>
              <text xml:space="preserve"> — validates paths, gates </text>
              <code xml:space="preserve">?xao:XML=1</code>
              <text xml:space="preserve"> / </text>
              <code xml:space="preserve">?xao:Text=1</code>
              <text xml:space="preserve"> behind </text>
              <code xml:space="preserve">$debug === true</code>
              <text xml:space="preserve">, transforms via </text>
              <code xml:space="preserve">Transformer</code>
              <text xml:space="preserve">, and returns an immutable </text>
              <code xml:space="preserve">Response</code>
              <text xml:space="preserve">.</text>
            </paragraph>
          </item>
        </list>
        <heading level="2">
          <code xml:space="preserve">Xao\Http\Response</code>
        </heading>
        <paragraph>
          <text xml:space="preserve">Source: </text>
          <code xml:space="preserve">src/Http/Response.php</code>
        </paragraph>
        <list type="bullet" tight="true">
          <item>
            <paragraph>
              <code xml:space="preserve">__construct(int $status, string $contentType, string $body, array $headers = [])</code>
            </paragraph>
          </item>
          <item>
            <paragraph>
              <code xml:space="preserve">getStatus(): int</code>
              <text xml:space="preserve">, </text>
              <code xml:space="preserve">getContentType(): string</code>
              <text xml:space="preserve">, </text>
              <code xml:space="preserve">getBody(): string</code>
              <text xml:space="preserve">, </text>
              <code xml:space="preserve">getHeaders(): array</code>
              <text xml:space="preserve">, </text>
              <code xml:space="preserve">emit(): void</code>
            </paragraph>
          </item>
        </list>
        <heading level="2">
          <code xml:space="preserve">Xao\Exceptions\*</code>
        </heading>
        <paragraph>
          <text xml:space="preserve">All exceptions extend </text>
          <code xml:space="preserve">Xao\Exceptions\XaoException</code>
          <text xml:space="preserve"> (</text>
          <code xml:space="preserve">getErrorCode()</code>
          <text xml:space="preserve">, </text>
          <code xml:space="preserve">getContext()</code>
          <text xml:space="preserve">, </text>
          <code xml:space="preserve">toErrorArray()</code>
          <text xml:space="preserve">):</text>
        </paragraph>
        <list type="bullet" tight="true">
          <item>
            <paragraph>
              <code xml:space="preserve">Xao\Exceptions\DomDocException</code>
            </paragraph>
          </item>
          <item>
            <paragraph>
              <code xml:space="preserve">Xao\Exceptions\XmlParseException</code>
            </paragraph>
          </item>
          <item>
            <paragraph>
              <code xml:space="preserve">Xao\Exceptions\DbToXmlException</code>
            </paragraph>
          </item>
          <item>
            <paragraph>
              <code xml:space="preserve">Xao\Exceptions\TransformException</code>
              <text xml:space="preserve"> (adds </text>
              <code xml:space="preserve">getHttpStatus(): int</code>
              <text xml:space="preserve">)</text>
            </paragraph>
          </item>
          <item>
            <paragraph>
              <code xml:space="preserve">Xao\Exceptions\XsltTransformException</code>
              <text xml:space="preserve"> (extends </text>
              <code xml:space="preserve">TransformException</code>
              <text xml:space="preserve"> for native/driver XSLT errors)</text>
            </paragraph>
          </item>
          <item>
            <paragraph>
              <code xml:space="preserve">Xao\Exceptions\InvalidSlugException</code>
              <text xml:space="preserve"> (adds </text>
              <code xml:space="preserve">getHttpStatus(): int</code>
              <text xml:space="preserve">)</text>
            </paragraph>
          </item>
        </list>
      </document>
    </body>
  </page>
</xao-docs>
