### Installing xast-util-from-xml with npm
Source: https://github.com/syntax-tree/xast-util-from-xml/blob/main/readme.md
This command installs the `xast-util-from-xml` package using npm. It is an ESM-only package and requires Node.js version 16 or higher for compatibility.
```sh
npm install xast-util-from-xml
```
--------------------------------
### Example XML Document for Parsing
Source: https://github.com/syntax-tree/xast-util-from-xml/blob/main/readme.md
This XML snippet represents a sample album document, used as input for the `xast-util-from-xml` utility. It includes an `album` element with an `id` attribute and nested `name`, `artist`, and `releasedate` elements.
```xml
Born in the U.S.A.
Bruce Springsteen
1984-04-06
```
--------------------------------
### Example Output of Parsed xast Tree
Source: https://github.com/syntax-tree/xast-util-from-xml/blob/main/readme.md
This JavaScript object literal represents the xast syntax tree generated by parsing the example XML document. It shows the hierarchical structure, including root, element, and text nodes, as produced by `fromXml`.
```js
{
type: 'root',
children: [
{
type: 'element',
name: 'album',
attributes: {id: '123'},
children: [
{type: 'text', value: '\n '},
{
type: 'element',
name: 'name',
attributes: {},
children: [{type: 'text', value: 'Born in the U.S.A.'}]
},
{type: 'text', value: '\n '},
{
type: 'element',
name: 'artist',
attributes: {},
children: [{type: 'text', value: 'Bruce Springsteen'}]
},
{type: 'text', value: '\n '},
{
type: 'element',
name: 'releasedate',
attributes: {},
children: [{type: 'text', value: '1984-04-06'}]
},
{type: 'text', value: '\n'}
]
}
]
}
```
--------------------------------
### Importing xast-util-from-xml in Browsers
Source: https://github.com/syntax-tree/xast-util-from-xml/blob/main/readme.md
This HTML script tag demonstrates how to import `xast-util-from-xml` directly in a browser environment using `esm.sh` with the `?bundle` query parameter for bundling.
```html
```
--------------------------------
### Importing xast-util-from-xml in Deno
Source: https://github.com/syntax-tree/xast-util-from-xml/blob/main/readme.md
This JavaScript import statement shows how to use `xast-util-from-xml` in a Deno environment, leveraging `esm.sh` for module resolution.
```js
import {fromXml} from 'https://esm.sh/xast-util-from-xml@4'
```
--------------------------------
### Parsing XML to xast Tree in Node.js
Source: https://github.com/syntax-tree/xast-util-from-xml/blob/main/readme.md
This JavaScript code demonstrates how to read an XML file asynchronously and parse its content into a xast syntax tree using `fromXml`. The resulting tree is then printed to the console for inspection.
```js
import fs from 'node:fs/promises'
import {fromXml} from 'xast-util-from-xml'
const tree = fromXml(await fs.readFile('example.xml'))
console.dir(tree, {depth: undefined})
```
=== COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.