8
8
[ ![ Backers] [ backers-badge ]] [ collective ]
9
9
[ ![ Chat] [ chat-badge ]] [ chat ]
10
10
11
- ** [ xast] [ ] ** utility to parse from XML.
11
+ [ xast] [ ] utility to parse from XML.
12
12
13
- ## Install
13
+ ## Contents
14
+
15
+ * [ What is this?] ( #what-is-this )
16
+ * [ When should I use this?] ( #when-should-i-use-this )
17
+ * [ Install] ( #install )
18
+ * [ Use] ( #use )
19
+ * [ API] ( #api )
20
+ * [ ` fromXml(value) ` ] ( #fromxmlvalue )
21
+ * [ Types] ( #types )
22
+ * [ Compatibility] ( #compatibility )
23
+ * [ Security] ( #security )
24
+ * [ Related] ( #related )
25
+ * [ Contribute] ( #contribute )
26
+ * [ License] ( #license )
27
+
28
+ ## What is this?
29
+
30
+ This package is a utility that takes XML input and turns it into a [ xast] [ ]
31
+ syntax tree.
32
+ It uses [ ` sax ` ] [ sax ] , which turns XML into events, while it turns those events
33
+ into nodes.
14
34
15
- This package is [ ESM only] ( https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c ) :
16
- Node 12+ is needed to use it and it must be ` import ` ed instead of ` require ` d.
35
+ ## When should I use this?
17
36
18
- [ npm] [ ] :
37
+ If you want to handle syntax trees, use this.
38
+ Use [ ` sax ` ] [ sax ] itself instead when you want to do other things.
39
+
40
+ The utility [ ` xast-util-to-xml ` ] [ xast-util-to-xml ] does the inverse of this
41
+ utility.
42
+ It turns xast into XML.
43
+
44
+ ## Install
45
+
46
+ This package is [ ESM only] [ esm ] .
47
+ In Node.js (version 12.20+, 14.14+, 16.0+, or 18.0+), install with [ npm] [ ] :
19
48
20
49
``` sh
21
50
npm install xast-util-from-xml
22
51
```
23
52
53
+ In Deno with [ ` esm.sh ` ] [ esmsh ] :
54
+
55
+ ``` js
56
+ import {fromXml } from ' https://esm.sh/xast-util-from-xml@2'
57
+ ```
58
+
59
+ In browsers with [ ` esm.sh ` ] [ esmsh ] :
60
+
61
+ ``` html
62
+ <script type =" module" >
63
+ import {fromXml } from ' https://esm.sh/xast-util-from-xml@2?bundle'
64
+ </script >
65
+ ```
66
+
24
67
## Use
25
68
26
- Say we have the following XML file, ` example.xml ` :
69
+ Say our document ` example.xml ` contains :
27
70
28
71
``` xml
29
72
<album id =" 123" >
@@ -33,20 +76,18 @@ Say we have the following XML file, `example.xml`:
33
76
</album >
34
77
```
35
78
36
- And our script, ` example.js ` , looks as follows:
79
+ …and our module ` example.js ` looks as follows:
37
80
38
81
``` js
39
- import fs from ' node:fs'
82
+ import fs from ' node:fs/promises '
40
83
import {fromXml } from ' xast-util-from-xml'
41
84
42
- const doc = fs .readFileSync (' example.xml' )
43
-
44
- const tree = fromXml (doc)
85
+ const tree = fromXml (await fs .readFile (' example.xml' ))
45
86
46
87
console .log (tree)
47
88
```
48
89
49
- Now, running ` node example ` yields (positional info removed for brevity):
90
+ …now running ` node example.js ` yields (positional info removed for brevity):
50
91
51
92
``` js
52
93
{
@@ -88,23 +129,35 @@ Now, running `node example` yields (positional info removed for brevity):
88
129
89
130
## API
90
131
91
- This package exports the following identifiers: ` fromXml ` .
132
+ This package exports the identifier ` fromXml ` .
92
133
There is no default export.
93
134
94
- ### ` fromXml(doc ) `
135
+ ### ` fromXml(value ) `
95
136
96
- Parse XML to a ** [ xast ] [ ] ** tree.
137
+ Turn XML into a syntax tree.
97
138
98
139
##### Parameters
99
140
100
- ###### ` doc `
141
+ ###### ` value `
101
142
102
143
Value to parse (` string ` or ` Buffer ` in UTF-8).
103
144
104
145
##### Returns
105
146
106
147
[ ` Root ` ] [ root ] .
107
148
149
+ ## Types
150
+
151
+ This package is fully typed with [ TypeScript] [ ] .
152
+ It exports no additional types.
153
+
154
+ ## Compatibility
155
+
156
+ Projects maintained by the unified collective are compatible with all maintained
157
+ versions of Node.js.
158
+ As of now, that is Node.js 12.20+, 14.14+, 16.0+, and 18.0+.
159
+ Our projects sometimes work with older versions, but this is not guaranteed.
160
+
108
161
## Security
109
162
110
163
XML can be a dangerous language: don’t trust user-provided data.
@@ -120,8 +173,8 @@ XML can be a dangerous language: don’t trust user-provided data.
120
173
121
174
## Contribute
122
175
123
- See [ ` contributing.md ` in ` syntax-tree/.github ` ] [ contributing ] for ways to get
124
- started.
176
+ See [ ` contributing.md ` ] [ contributing ] in [ ` syntax-tree/.github ` ] [ health ] for
177
+ ways to get started.
125
178
See [ ` support.md ` ] [ support ] for ways to get help.
126
179
127
180
This project has a [ code of conduct] [ coc ] .
@@ -162,16 +215,28 @@ abide by its terms.
162
215
163
216
[ npm ] : https://docs.npmjs.com/cli/install
164
217
218
+ [ esm ] : https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c
219
+
220
+ [ esmsh ] : https://esm.sh
221
+
222
+ [ typescript ] : https://www.typescriptlang.org
223
+
165
224
[ license ] : license
166
225
167
226
[ author ] : https://wooorm.com
168
227
169
- [ contributing ] : https://github.com/syntax-tree/.github/blob/HEAD/contributing.md
228
+ [ health ] : https://github.com/syntax-tree/.github
170
229
171
- [ support ] : https://github.com/syntax-tree/.github/blob/HEAD/support .md
230
+ [ contributing ] : https://github.com/syntax-tree/.github/blob/main/contributing .md
172
231
173
- [ coc ] : https://github.com/syntax-tree/.github/blob/HEAD/code-of-conduct.md
232
+ [ support ] : https://github.com/syntax-tree/.github/blob/main/support.md
233
+
234
+ [ coc ] : https://github.com/syntax-tree/.github/blob/main/code-of-conduct.md
174
235
175
236
[ xast ] : https://github.com/syntax-tree/xast
176
237
177
238
[ root ] : https://github.com/syntax-tree/xast#root
239
+
240
+ [ sax ] : https://github.com/isaacs/sax-js
241
+
242
+ [ xast-util-to-xml ] : https://github.com/syntax-tree/xast-util-to-xml
0 commit comments