{"id":13716987,"url":"https://github.com/syntax-tree/xast-util-from-xml","last_synced_at":"2025-09-05T03:33:31.210Z","repository":{"id":43380496,"uuid":"240505177","full_name":"syntax-tree/xast-util-from-xml","owner":"syntax-tree","description":"utility to parse from XML","archived":false,"fork":false,"pushed_at":"2023-07-18T15:17:27.000Z","size":111,"stargazers_count":17,"open_issues_count":0,"forks_count":2,"subscribers_count":8,"default_branch":"main","last_synced_at":"2025-04-22T07:41:52.667Z","etag":null,"topics":["parse","syntax-tree","unist","util","xast","xast-util","xml"],"latest_commit_sha":null,"homepage":"https://unifiedjs.com","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/syntax-tree.png","metadata":{"funding":{"github":"unifiedjs","open_collective":"unified"},"files":{"readme":"readme.md","changelog":null,"contributing":null,"funding":null,"license":"license","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null}},"created_at":"2020-02-14T12:39:03.000Z","updated_at":"2025-01-10T20:09:15.000Z","dependencies_parsed_at":"2024-01-14T20:16:54.444Z","dependency_job_id":"cd9f924b-83f6-49ec-a818-cc9df42736e4","html_url":"https://github.com/syntax-tree/xast-util-from-xml","commit_stats":{"total_commits":39,"total_committers":2,"mean_commits":19.5,"dds":0.02564102564102566,"last_synced_commit":"9a84c7c3d43ac82c991a5d6c9092248afaa37bf9"},"previous_names":[],"tags_count":7,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/syntax-tree%2Fxast-util-from-xml","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/syntax-tree%2Fxast-util-from-xml/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/syntax-tree%2Fxast-util-from-xml/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/syntax-tree%2Fxast-util-from-xml/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/syntax-tree","download_url":"https://codeload.github.com/syntax-tree/xast-util-from-xml/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252826890,"owners_count":21810200,"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","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":["parse","syntax-tree","unist","util","xast","xast-util","xml"],"created_at":"2024-08-03T00:01:16.335Z","updated_at":"2025-05-07T06:31:48.061Z","avatar_url":"https://github.com/syntax-tree.png","language":"JavaScript","readme":"# xast-util-from-xml\n\n[![Build][build-badge]][build]\n[![Coverage][coverage-badge]][coverage]\n[![Downloads][downloads-badge]][downloads]\n[![Size][size-badge]][size]\n[![Sponsors][sponsors-badge]][collective]\n[![Backers][backers-badge]][collective]\n[![Chat][chat-badge]][chat]\n\n[xast][] utility to parse from XML.\n\n## Contents\n\n*   [What is this?](#what-is-this)\n*   [When should I use this?](#when-should-i-use-this)\n*   [Install](#install)\n*   [Use](#use)\n*   [API](#api)\n    *   [`fromXml(value)`](#fromxmlvalue)\n*   [Types](#types)\n*   [Compatibility](#compatibility)\n*   [Security](#security)\n*   [Related](#related)\n*   [Contribute](#contribute)\n*   [License](#license)\n\n## What is this?\n\nThis package is a utility that takes serialized XML as input and turns it into\na [xast][] syntax tree.\nIt uses [`@rgrove/parse-xml`][parse-xml], which is a good and fast XML parser,\nand turns its results into xast.\n\n## When should I use this?\n\nIf you want to use xast syntax trees, use this.\n\nThe utility [`xast-util-to-xml`][xast-util-to-xml] does the inverse of this\nutility.\nIt turns xast into XML.\n\n## Install\n\nThis package is [ESM only][esm].\nIn Node.js (version 16+), install with [npm][]:\n\n```sh\nnpm install xast-util-from-xml\n```\n\nIn Deno with [`esm.sh`][esmsh]:\n\n```js\nimport {fromXml} from 'https://esm.sh/xast-util-from-xml@4'\n```\n\nIn browsers with [`esm.sh`][esmsh]:\n\n```html\n\u003cscript type=\"module\"\u003e\n  import {fromXml} from 'https://esm.sh/xast-util-from-xml@4?bundle'\n\u003c/script\u003e\n```\n\n## Use\n\nSay our document `example.xml` contains:\n\n```xml\n\u003calbum id=\"123\"\u003e\n  \u003cname\u003eBorn in the U.S.A.\u003c/name\u003e\n  \u003cartist\u003eBruce Springsteen\u003c/artist\u003e\n  \u003creleasedate\u003e1984-04-06\u003c/releasedate\u003e\n\u003c/album\u003e\n```\n\n…and our module `example.js` looks as follows:\n\n```js\nimport fs from 'node:fs/promises'\nimport {fromXml} from 'xast-util-from-xml'\n\nconst tree = fromXml(await fs.readFile('example.xml'))\n\nconsole.dir(tree, {depth: undefined})\n```\n\n…now running `node example.js` yields (positional info removed for brevity):\n\n```js\n{\n  type: 'root',\n  children: [\n    {\n      type: 'element',\n      name: 'album',\n      attributes: {id: '123'},\n      children: [\n        {type: 'text', value: '\\n  '},\n        {\n          type: 'element',\n          name: 'name',\n          attributes: {},\n          children: [{type: 'text', value: 'Born in the U.S.A.'}]\n        },\n        {type: 'text', value: '\\n  '},\n        {\n          type: 'element',\n          name: 'artist',\n          attributes: {},\n          children: [{type: 'text', value: 'Bruce Springsteen'}]\n        },\n        {type: 'text', value: '\\n  '},\n        {\n          type: 'element',\n          name: 'releasedate',\n          attributes: {},\n          children: [{type: 'text', value: '1984-04-06'}]\n        },\n        {type: 'text', value: '\\n'}\n      ]\n    }\n  ]\n}\n```\n\n## API\n\nThis package exports the identifier [`fromXml`][api-from-xml].\nThere is no default export.\n\n### `fromXml(value)`\n\nParse a string of XML to a xast tree.\n\n##### Parameters\n\n*   `value` (`Uint8Array` in UTF-8 or `string`).\n    — serialized XML\n\n##### Returns\n\nxast root ([`Root`][root]).\n\n###### Throws\n\nWhen the XML cannot be parsed with `@rgrove/parse-xml`, a\n[`VFileMessage`][vfile-message] is thrown.\n\nThis can for example happen when passing archaic or unsafe XML (such as\nentities), or just otherwise invalid XML such as missnested tags.\n\n## Types\n\nThis package is fully typed with [TypeScript][].\nIt exports no additional types.\n\n## Compatibility\n\nProjects maintained by the unified collective are compatible with maintained\nversions of Node.js.\n\nWhen we cut a new major release, we drop support for unmaintained versions of\nNode.\nThis means we try to keep the current release line, `xast-util-from-xml@^4`,\ncompatible with Node.js 16.\n\n## Security\n\nXML can be a dangerous language: don’t trust user-provided data.\n\n## Related\n\n*   [`xast-util-to-xml`](https://github.com/syntax-tree/xast-util-to-xml)\n    — serialize xast to XML\n*   [`hast-util-to-xast`](https://github.com/syntax-tree/hast-util-to-xast)\n    — transform hast (html, svg) to xast (xml)\n*   [`xastscript`](https://github.com/syntax-tree/xastscript)\n    — create xast trees\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.\n\nThis project has a [code of conduct][coc].\nBy interacting with this repository, organization, or community you agree to\nabide by its terms.\n\n## License\n\n[MIT][license] © [Titus Wormer][author]\n\n\u003c!-- Definitions --\u003e\n\n[build-badge]: https://github.com/syntax-tree/xast-util-from-xml/workflows/main/badge.svg\n\n[build]: https://github.com/syntax-tree/xast-util-from-xml/actions\n\n[coverage-badge]: https://img.shields.io/codecov/c/github/syntax-tree/xast-util-from-xml.svg\n\n[coverage]: https://codecov.io/github/syntax-tree/xast-util-from-xml\n\n[downloads-badge]: https://img.shields.io/npm/dm/xast-util-from-xml.svg\n\n[downloads]: https://www.npmjs.com/package/xast-util-from-xml\n\n[size-badge]: https://img.shields.io/badge/dynamic/json?label=minzipped%20size\u0026query=$.size.compressedSize\u0026url=https://deno.bundlejs.com/?q=xast-util-from-xml\n\n[size]: https://bundlejs.com/?q=xast-util-from-xml\n\n[sponsors-badge]: https://opencollective.com/unified/sponsors/badge.svg\n\n[backers-badge]: https://opencollective.com/unified/backers/badge.svg\n\n[collective]: https://opencollective.com/unified\n\n[chat-badge]: https://img.shields.io/badge/chat-discussions-success.svg\n\n[chat]: https://github.com/syntax-tree/unist/discussions\n\n[npm]: https://docs.npmjs.com/cli/install\n\n[esm]: https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c\n\n[esmsh]: https://esm.sh\n\n[typescript]: https://www.typescriptlang.org\n\n[license]: license\n\n[author]: https://wooorm.com\n\n[health]: https://github.com/syntax-tree/.github\n\n[contributing]: https://github.com/syntax-tree/.github/blob/main/contributing.md\n\n[support]: https://github.com/syntax-tree/.github/blob/main/support.md\n\n[coc]: https://github.com/syntax-tree/.github/blob/main/code-of-conduct.md\n\n[xast]: https://github.com/syntax-tree/xast\n\n[root]: https://github.com/syntax-tree/xast#root\n\n[vfile-message]: https://github.com/vfile/vfile-message\n\n[parse-xml]: https://github.com/rgrove/parse-xml\n\n[xast-util-to-xml]: https://github.com/syntax-tree/xast-util-to-xml\n\n[api-from-xml]: #fromxmlvalue\n","funding_links":["https://github.com/sponsors/unifiedjs","https://opencollective.com/unified"],"categories":["xast utilities","JavaScript"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsyntax-tree%2Fxast-util-from-xml","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsyntax-tree%2Fxast-util-from-xml","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsyntax-tree%2Fxast-util-from-xml/lists"}