XFA Packet DOM

TXFAPacketDOM loads either a complete XDP stream or an ordered PDF /XFA packet array, exposes packet roots and bounded local-name path queries, and supports element, text, CDATA, attribute, packet-add, packet-remove, and packet-rename edits

Lossless untouched packets

Each loaded stream or packet keeps its original bytes and a structural fingerprint; serialization returns those exact bytes when the DOM is untouched, and a packet-array edit rewrites only the changed packet while byte-preserving every unchanged sibling

Canonical modified output

Modified trees use UTF-8 XML, deterministic namespace and attribute order, qualified element names, XML entity escaping, safe CDATA splitting for embedded ]]>, self-closing empty elements, and packet order from the source array

Canonical output represents DOM content rather than lexical trivia, so comments, processing instructions, source indentation, the original XML declaration, and a source DOCTYPE are not replayed after an edit; internal entity values are expanded as text and external entities remain unresolved

Queries and edits

var
  DOM: TXFAPacketDOM;
  Nodes: TArray<TXFANode>;
  XDP: TBytes;
begin
  DOM := TXFAPacketDOM.Create;
  try
    DOM.LoadXDPStream(SourceBytes);
    Nodes := DOM.SelectNodes('datasets', '//customer/name');
    if Length(Nodes) > 0 then
      Nodes[0].SetText('Updated & verified', True);
    XDP := DOM.SerializeXDPStream;
    PDF.SetXFADocument(XDP);
  finally
    DOM.Free;
  end;
end;

A leading // performs a bounded descendant query, while slash-separated segments select direct children; * matches any element and a zero-based [N] suffix selects one match

Packet-array publication

SerializePacketArray returns ordered TXFAPacketData records; pass each record to THotPDF.AddXFAPacket, or use SerializeXDPStream with THotPDF.SetXFADocument for the single-stream form

Budgets

TXFADOMLimits.Default bounds aggregate input and output bytes, packet count, node count, depth, attributes per node, aggregate attribute and text bytes, and MaxQueryResults; parsing, mutation validation, querying, fingerprinting, and serialization fail with EHPDFXFAError when a boundary is crossed

See TXFAPacketDOM, TXFANode, and TXFADOMLimits