{"id":13716489,"url":"https://github.com/syntax-tree/xast","last_synced_at":"2026-03-05T20:45:06.916Z","repository":{"id":43396597,"uuid":"231241397","full_name":"syntax-tree/xast","owner":"syntax-tree","description":"Extensible Abstract Syntax Tree","archived":false,"fork":false,"pushed_at":"2024-10-04T12:56:12.000Z","size":68,"stargazers_count":87,"open_issues_count":0,"forks_count":2,"subscribers_count":9,"default_branch":"main","last_synced_at":"2025-10-08T03:39:22.019Z","etag":null,"topics":["ast","extensible","language","markup","syntax-tree","unist","xast","xml"],"latest_commit_sha":null,"homepage":"https://unifiedjs.com","language":null,"has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/syntax-tree.png","metadata":{"funding":{"github":"unifiedjs","open_collective":"unified","thanks_dev":"u/gh/syntax-tree"},"files":{"readme":"readme.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2020-01-01T16:58:24.000Z","updated_at":"2025-09-23T02:44:14.000Z","dependencies_parsed_at":"2024-11-14T04:31:46.816Z","dependency_job_id":null,"html_url":"https://github.com/syntax-tree/xast","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/syntax-tree/xast","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/syntax-tree%2Fxast","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/syntax-tree%2Fxast/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/syntax-tree%2Fxast/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/syntax-tree%2Fxast/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/syntax-tree","download_url":"https://codeload.github.com/syntax-tree/xast/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/syntax-tree%2Fxast/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":279020361,"owners_count":26086866,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-10-14T02:00:06.444Z","response_time":60,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["ast","extensible","language","markup","syntax-tree","unist","xast","xml"],"created_at":"2024-08-03T00:01:10.987Z","updated_at":"2025-10-14T18:41:31.595Z","avatar_url":"https://github.com/syntax-tree.png","language":null,"readme":"# ![xast][logo]\n\nE**x**tensible **A**bstract **S**yntax **T**ree format.\n\n***\n\n**xast** is a specification for representing [XML][] as an abstract\n[syntax tree][syntax-tree].\nIt implements the **[unist][]** spec.\n\nThis document may not be released.\nSee [releases][] for released documents.\nThe latest released version is [`1.0.0`][latest].\n\n## Contents\n\n* [Introduction](#introduction)\n  * [Where this specification fits](#where-this-specification-fits)\n  * [Scope](#scope)\n* [Types](#types)\n* [Nodes (abstract)](#nodes-abstract)\n  * [`Literal`](#literal)\n  * [`Parent`](#parent)\n* [Nodes](#nodes)\n  * [`Cdata`](#cdata)\n  * [`Comment`](#comment)\n  * [`Doctype`](#doctype)\n  * [`Element`](#element)\n  * [`Instruction`](#instruction)\n  * [`Root`](#root)\n  * [`Text`](#text)\n* [Other types](#other-types)\n  * [`Attributes`](#attributes)\n  * [`AttributeName`](#attributename)\n  * [`AttributeValue`](#attributevalue)\n* [Glossary](#glossary)\n* [List of utilities](#list-of-utilities)\n* [References](#references)\n* [Related](#related)\n* [Contribute](#contribute)\n* [Acknowledgments](#acknowledgments)\n* [License](#license)\n\n## Introduction\n\nThis document defines a format for representing XML as an [abstract syntax\ntree][syntax-tree].\nThis specification is written in a [Web IDL][webidl]-like grammar.\nDevelopment started in January 2020.\n\n### Where this specification fits\n\nxast extends [unist][],\na format for syntax trees,\nto benefit from its [ecosystem of utilities][utilities].\n\nxast relates to [JavaScript][] in that it has an [ecosystem of\nutilities][list-of-utilities] for working with compliant syntax trees in\nJavaScript.\nHowever,\nxast is not limited to JavaScript and can be used in other programming\nlanguages.\n\nxast relates to the [unified][] project in that xast syntax trees are used\nthroughout its ecosystem.\n\n### Scope\n\nxast represents XML syntax,\nnot semantics:\nthere are no namespaces or local names;\nonly qualified names.\n\nxast supports a sensible subset of XML by omitting the ostensibly bad DTD.\nXML processors are not guaranteed to process DTDs,\nmaking them unsafe.\n\nxast represents expanded entities and therefore does not deal with entities or\ncharacter references.\nIt is suggested that utilities around xast,\nthat parse or serialize,\ndo *not* support *[parameter-entity references][concept-parameter-entity]* or\n*[entity references][concept-entity]* other than the\n*[predefined entities][concept-predefined-entities]*\n(`\u0026lt;` for `\u003c` U+003C LESS THAN;\n`\u0026gt;` for `\u003e` U+003E GREATER THAN;\n`\u0026amp;` for `\u0026` U+0026 AMPERSAND;\n`\u0026apos;` for `'` U+0027 APOSTROPHE;\n`\u0026quot;` for `\"` U+0022 QUOTATION MARK).\nThis prevents *[billion laughs][billion-laughs]* attacks.\n\n###### Declarations\n\n*[Declarations][concept-declaration]* ([\\[XML\\]][xml]) other than\n[doctype][dfn-doctype] have no representation in xast:\n\n```xml\n\u003c!ELEMENT %name.para; %content.para;\u003e\n\u003c!ATTLIST poem xml:space (default|preserve) 'preserve'\u003e\n\u003c!ENTITY % ISOLat2 SYSTEM \"http://www.xml.com/iso/isolat2-xml.entities\"\u003e\n\u003c!ENTITY Pub-Status \"This is a pre-release of the specification.\"\u003e\n\u003c![%draft;[\u003c!ELEMENT book (comments*, title, body, supplements?)\u003e]]\u003e\n\u003c![%final;[\u003c!ELEMENT book (title, body, supplements?)\u003e]]\u003e\n```\n\n###### Internal subset\n\nInternal document type declarations have no representation in xast:\n\n```xml\n\u003c!DOCTYPE greeting [\n  \u003c!ELEMENT greeting (#PCDATA)\u003e\n]\u003e\n\u003cgreeting\u003eHello, world!\u003c/greeting\u003e\n```\n\n## Types\n\nIf you are using TypeScript,\nyou can use the xast types by installing them with npm:\n\n```sh\nnpm install @types/xast\n```\n\n## Nodes (abstract)\n\n### `Literal`\n\n```idl\ninterface Literal \u003c: UnistLiteral {\n  value: string\n}\n```\n\n**Literal** (**[UnistLiteral][dfn-unist-literal]**) represents a node in xast\ncontaining a value.\n\n### `Parent`\n\n```idl\ninterface Parent \u003c: UnistParent {\n  children: [Cdata | Comment | Doctype | Element | Instruction | Text]\n}\n```\n\n**Parent** (**[UnistParent][dfn-unist-parent]**) represents a node in xast\ncontaining other nodes (said to be *[children][term-child]*).\n\nIts content is limited to only other xast content.\n\n## Nodes\n\n### `Cdata`\n\n```idl\ninterface Cdata \u003c: Literal {\n  type: 'cdata'\n}\n```\n\n**Cdata** (**[Literal][dfn-literal]**) represents a\n*[CDATA section][concept-cdata]* ([\\[XML\\]][xml]).\n\nFor example,\nthe following XML:\n\n```xml\n\u003c![CDATA[\u003cgreeting\u003eHello, world!\u003c/greeting\u003e]]\u003e\n```\n\nYields:\n\n```js\n{\n  type: 'cdata',\n  value: '\u003cgreeting\u003eHello, world!\u003c/greeting\u003e'\n}\n```\n\n### `Comment`\n\n```idl\ninterface Comment \u003c: Literal {\n  type: 'comment'\n}\n```\n\n**Comment** (**[Literal][dfn-literal]**) represents a\n*[comment][concept-comment]* ([\\[XML\\]][xml]).\n\nFor example,\nthe following XML:\n\n```xml\n\u003c!--Charlie--\u003e\n```\n\nYields:\n\n```js\n{type: 'comment', value: 'Charlie'}\n```\n\n### `Doctype`\n\n```idl\ninterface Doctype \u003c: Node {\n  type: 'doctype'\n  name: string\n  public: string?\n  system: string?\n}\n```\n\n**Doctype** (**[Node][dfn-unist-node]**) represents a\n*[doctype][concept-doctype]* ([\\[XML\\]][xml]).\n\nA `name` field must be present.\n\nA `public` field should be present.\nIf present,\nit must be set to a string,\nand represents the document’s public identifier.\n\nA `system` field should be present.\nIf present,\nit must be set to a string,\nand represents the document’s system identifier.\n\nFor example,\nthe following XML:\n\n```xml\n\u003c!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0 Transitional//EN\" \"http://www.w3.org/TR/REC-html40/loose.dtd\"\u003e\n```\n\nYields:\n\n```js\n{\n  type: 'doctype',\n  name: 'HTML',\n  public: '-//W3C//DTD HTML 4.0 Transitional//EN',\n  system: 'http://www.w3.org/TR/REC-html40/loose.dtd'\n}\n```\n\n### `Element`\n\n```idl\ninterface Element \u003c: Parent {\n  type: 'element'\n  name: string\n  attributes: Attributes?\n  children: [Cdata | Comment | Element | Instruction | Text]\n}\n```\n\n**Element** (**[Parent][dfn-parent]**) represents an\n*[element][concept-element]* ([\\[XML\\]][xml]).\n\nThe `name` field must be present.\nIt represents the element’s *[name][concept-name]* ([\\[XML\\]][xml]),\nspecifically its *[qualified name][concept-qualified-name]*\n([\\[XML-NAMES\\]][xml-names]).\n\nThe `children` field should be present.\n\nThe `attributes` field should be present.\nIt represents information associated with the element.\nThe value of the `attributes` field implements the\n**[Attributes][dfn-attributes]** interface.\n\nFor example,\nthe following XML:\n\n```xml\n\u003cpackage unique-identifier=\"id\" xmlns=\"http://www.idpf.org/2007/opf\" /\u003e\n```\n\nYields:\n\n```js\n{\n  type: 'element',\n  name: 'package',\n  attributes: {\n    'unique-identifier': 'id',\n    xmlns: 'http://www.idpf.org/2007/opf'\n  },\n  children: []\n}\n```\n\n### `Instruction`\n\n```idl\ninterface Instruction \u003c: Literal {\n  type: 'instruction'\n  name: string\n}\n```\n\n**Instruction** (**[Literal][dfn-literal]**) represents a\n*[processing instruction][concept-instruction]* ([\\[XML\\]][xml]).\n\nA `name` field must be present.\n\nFor example,\nthe following XML:\n\n```xml\n\u003c?xml version=\"1.0\" encoding=\"UTF-8\"?\u003e\n```\n\nYields:\n\n```js\n{\n  type: 'instruction',\n  name: 'xml',\n  value: 'version=\"1.0\" encoding=\"UTF-8\"'\n}\n```\n\n### `Root`\n\n```idl\ninterface Root \u003c: Parent {\n  type: 'root'\n}\n```\n\n**Root** (**[Parent][dfn-parent]**) represents a document fragment or a whole\ndocument.\n\n**Root** should be used as the *[root][term-root]* of a *[tree][term-tree]* and\nmust not be used as a *[child][term-child]*.\n\nXML specifies that documents should have exactly one **[element][dfn-element]**\nchild,\ntherefore a root should have exactly one element child when representing a\nwhole document.\n\n### `Text`\n\n```idl\ninterface Text \u003c: Literal {\n  type: 'text'\n}\n```\n\n**Text** (**[Literal][dfn-literal]**) represents\n*[character data][concept-char]* ([\\[XML\\]][xml]).\n\nFor example,\nthe following XML:\n\n```xml\n\u003cdc:language\u003een\u003c/dc:language\u003e\n```\n\nYields:\n\n```js\n{\n  type: 'element',\n  name: 'dc:language',\n  attributes: {},\n  children: [{type: 'text', value: 'en'}]\n}\n```\n\n## Other types\n\n### `Attributes`\n\n```idl\ninterface Attributes {}\n```\n\n**Attributes** represents information associated with an element.\n\nEvery field must be a **[AttributeName][dfn-attribute-name]** and every value an\n**[AttributeValue][dfn-attribute-value]**.\n\n### `AttributeName`\n\n```idl\ntypedef string AttributeName\n```\n\nAttribute names are keys on **[Attributes][dfn-attributes]** objects and must\nreflect XML attribute names exactly.\n\n### `AttributeValue`\n\n```idl\ntypedef string AttributeValue\n```\n\nAttribute values are values on **[Attributes][dfn-attributes]** objects and must\nreflect XML attribute values exactly as a string.\n\n\u003e In [JSON][],\n\u003e the value `null` must be treated as if the attribute was not included.\n\u003e In [JavaScript][],\n\u003e both `null` and `undefined` must be similarly ignored.\n\n## Glossary\n\nSee the [unist glossary][glossary].\n\n## List of utilities\n\nSee the [unist list of utilities][utilities] for more utilities.\n\n* [`xastscript`](https://github.com/syntax-tree/xastscript)\n  — create trees\n* [`xast-util-feed`](https://github.com/syntax-tree/xast-util-feed)\n  — build feeds (RSS, Atom)\n* [`xast-util-from-xml`](https://github.com/syntax-tree/xast-util-from-xml)\n  — parse from XML\n* [`xast-util-sitemap`](https://github.com/syntax-tree/xast-util-sitemap)\n  — build `sitemap.xml`\n* [`xast-util-to-string`](https://github.com/syntax-tree/xast-util-to-string)\n  — get the text value\n* [`xast-util-to-xml`](https://github.com/syntax-tree/xast-util-to-xml)\n  — serialize to XML\n* [`hast-util-to-xast`](https://github.com/syntax-tree/hast-util-to-xast)\n  — transform to xast\n\n## References\n\n* **JSON**\n  [The JavaScript Object Notation (JSON) Data Interchange Format][json],\n  T. Bray.\n  IETF.\n* **JavaScript**:\n  [ECMAScript Language Specification][javascript].\n  Ecma International.\n* **unist**:\n  [Universal Syntax Tree][unist].\n  T. Wormer; et al.\n* **XML**:\n  [Extensible Markup Language (XML) 1.0 (Fifth Edition)][xml]\n  T. Bray; et al.\n  W3C.\n* **XML-NAMES**:\n  [Namespaces in XML 1.0 (Third Edition)][xml-names]\n  T. Bray; et al.\n  W3C.\n* **Web IDL**:\n  [Web IDL][webidl],\n  C. McCormack.\n  W3C.\n\n## Related\n\n* [hast](https://github.com/syntax-tree/hast)\n  — Hypertext Abstract Syntax Tree format\n* [mdast](https://github.com/syntax-tree/mdast)\n  — Markdown Abstract Syntax Tree format\n* [nlcst](https://github.com/syntax-tree/nlcst)\n  — Natural Language Concrete Syntax Tree format\n\n## Contribute\n\nSee [`contributing.md`][contributing] in [`syntax-tree/.github`][health] for\nways to get started.\nSee [`support.md`][support] for ways to get help.\nIdeas for new utilities and tools can be posted in [`syntax-tree/ideas`][ideas].\n\nA curated list of awesome `syntax-tree`,\nunist,\nhast,\nmdast,\nnlcst,\nand xast resources can be found in [awesome syntax-tree][awesome].\n\nThis project has a [code of conduct][coc].\nBy interacting with this repository,\norganization,\nor community you agree to abide by its terms.\n\n## Acknowledgments\n\nThe initial release of this project was authored by **[@wooorm][author]**.\n\n## License\n\n[CC-BY-4.0][license] © [Titus Wormer][author]\n\n\u003c!-- Definitions --\u003e\n\n[health]: https://github.com/syntax-tree/.github\n\n[contributing]: https://github.com/syntax-tree/.github/blob/HEAD/contributing.md\n\n[support]: https://github.com/syntax-tree/.github/blob/HEAD/support.md\n\n[coc]: https://github.com/syntax-tree/.github/blob/HEAD/code-of-conduct.md\n\n[awesome]: https://github.com/syntax-tree/awesome-syntax-tree\n\n[ideas]: https://github.com/syntax-tree/ideas\n\n[license]: https://creativecommons.org/licenses/by/4.0/\n\n[author]: https://wooorm.com\n\n[logo]: https://raw.githubusercontent.com/syntax-tree/xast/c91a0c9/logo.svg?sanitize=true\n\n[releases]: https://github.com/syntax-tree/xast/releases\n\n[latest]: https://github.com/syntax-tree/xast/releases/tag/1.0.0\n\n[dfn-unist-node]: https://github.com/syntax-tree/unist#node\n\n[dfn-unist-parent]: https://github.com/syntax-tree/unist#parent\n\n[dfn-unist-literal]: https://github.com/syntax-tree/unist#literal\n\n[unist]: https://github.com/syntax-tree/unist\n\n[syntax-tree]: https://github.com/syntax-tree/unist#syntax-tree\n\n[javascript]: https://www.ecma-international.org/ecma-262/9.0/index.html\n\n[xml]: https://www.w3.org/TR/xml/\n\n[xml-names]: https://www.w3.org/TR/xml-names/\n\n[json]: https://tools.ietf.org/html/rfc7159\n\n[webidl]: https://heycam.github.io/webidl/\n\n[billion-laughs]: https://en.wikipedia.org/wiki/Billion_laughs_attack\n\n[glossary]: https://github.com/syntax-tree/unist#glossary\n\n[utilities]: https://github.com/syntax-tree/unist#list-of-utilities\n\n[unified]: https://github.com/unifiedjs/unified\n\n[concept-parameter-entity]: https://www.w3.org/TR/xml/#dt-PERef\n\n[concept-entity]: https://www.w3.org/TR/xml/#dt-entref\n\n[concept-predefined-entities]: https://www.w3.org/TR/xml/#sec-predefined-ent\n\n[concept-element]: https://www.w3.org/TR/xml/#NT-element\n\n[concept-name]: https://www.w3.org/TR/xml/#NT-Name\n\n[concept-char]: https://www.w3.org/TR/xml/#NT-Char\n\n[concept-comment]: https://www.w3.org/TR/xml/#NT-Comment\n\n[concept-doctype]: https://www.w3.org/TR/xml/#NT-doctypedecl\n\n[concept-instruction]: https://www.w3.org/TR/xml/#NT-PI\n\n[concept-declaration]: https://www.w3.org/TR/xml/#dt-markupdecl\n\n[concept-cdata]: https://www.w3.org/TR/xml/#NT-CDSect\n\n[concept-qualified-name]: https://www.w3.org/TR/xml-names/#NT-QName\n\n[term-tree]: https://github.com/syntax-tree/unist#tree\n\n[term-child]: https://github.com/syntax-tree/unist#child\n\n[term-root]: https://github.com/syntax-tree/unist#root\n\n[list-of-utilities]: #list-of-utilities\n\n[dfn-parent]: #parent\n\n[dfn-literal]: #literal\n\n[dfn-element]: #element\n\n[dfn-attributes]: #attributes\n\n[dfn-attribute-name]: #attributename\n\n[dfn-attribute-value]: #attributevalue\n\n[dfn-doctype]: #doctype\n","funding_links":["https://github.com/sponsors/unifiedjs","https://opencollective.com/unified","https://thanks.dev/u/gh/syntax-tree"],"categories":["Others","xast utilities"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsyntax-tree%2Fxast","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsyntax-tree%2Fxast","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsyntax-tree%2Fxast/lists"}