@nhtio/adk/batteries/artifacts/xml
A structured artifact battery for XML documents.
Remarks
Provides SpooledXmlArtifact — a SpooledArtifact specialisation that parses XML into a JSON projection and offers path-based query tools over that projection. The XML-to-JSON mapping defaults to ignoreAttributes: false and attributeNamePrefix: '_', both settable per instance through the constructor; preserveOrder: false is fixed. Under the default mapping:
- Element attributes become keys prefixed with
_(e.g.,root-elementwithhref="x"becomes{ a: { _href: 'x', ... } }). - Element text content becomes a
#textkey when the element also has attributes or siblings. - Repeated sibling elements collapse into an array.
- The full projection is queryable via JSONPath expressions (e.g.,
$..namefinds all name elements anywhere in the tree). Attributes are accessed via underscore-prefixed keys, e.g.$..["_href"]for the href attribute (recursive descent).
The battery also exports two converter Tool constants: xmlToJsonTool and jsonToXmlTool. These accept either inline XML/JSON text or a reference to an artifact produced earlier in the turn, and return the converted result as a new SpooledJsonArtifact or SpooledXmlArtifact.
Battery exceptions are defined in this module's exceptions.ts file — createException re-exported from @nhtio/adk/factories. Decoding a SpooledXmlArtifact instance via decode() throws until registerArtifactEncodables() has run (see @nhtio/adk/batteries/artifacts!registerArtifactEncodables).
Classes
| Class | Description |
|---|---|
| SpooledXmlArtifact | A @nhtio/adk!SpooledArtifact specialisation that adds XML-aware read operations. |
Variables
| Variable | Description |
|---|---|
| jsonToXmlTool | A tool that converts JSON (inline or from an artifact) to XML. |
| xmlToJsonTool | A tool that converts XML (inline or from an artifact) to JSON. |
References
E_XML_PARSE_FAILED
Re-exports E_XML_PARSE_FAILED
E_XML_PARSER_PEER_MISSING
Re-exports E_XML_PARSER_PEER_MISSING