π± Collection of carefully crafted TypeScript standalone libraries. Minimal, unbloated, convenient.
Attributes
Very Popular
Repository
Current version released
4 years ago
Versions
- 6.0.4Latest
- 6.0.3
- 6.0.2
- 6.0.1
- 6.0.0
- 5.4.16
- 5.4.15
- 5.4.14
- 5.4.13
- 5.4.12
- 5.4.11
- 5.4.10
- 5.4.9
- 5.4.8
- 5.4.7
- 5.4.6
- 5.4.2
- 5.4.1
- 5.4.0
- bundle-9.0.2
- bundle-9.0.1
- bundle-9.0.0
- testing-1.0.10
- run-1.0.1
- run-1.0.0
- bundle-8.0.0
- testing-1.0.9
- 5.3.1
- 4.0.0
- 3.0.2
- 3.0.0
- 2.1.3
- 2.1.2
- 2.1.1
- 2.1.1
- 2.1.0
- 2.0.4
- 2.0.3
- 2.0.2
- 2.0.1
- 2.0.0
- v1.0.3
- v1.0.2
- v1.0.1
- v1.0.0
- v0.0.2
- v0.0.1
- v.0.0.1
XML parser for Deno
Features
Follow XML.comβs Converting between XML and JSON patterns.
- Support basic XML (tags, self-closed tags, nested tags, attributes, β¦)
- Support
XML.parse
andXML.stringify
- Support
<?xml ?>
prolog declaration - Support
<!DOCTYPE>
declaration - Support
<![CDATA[ ]]
strings - Support XML entities (
&
,&
,&
, β¦) - Support
reviver
s for custom parsing - Auto-group nodes into arrays when same tag is used
- Auto-unwrap nodes when it only has text content
How reliable is deno.land/x/xml
? Check parse tests and
stringify tests π§ͺ
Limitations
- Comments are stripped and cannot be recovered
- When using mixed content of texts and child nodes, text node will be stripped and cannot be recovered
- When using mixed group of nodes,
XML.stringify(XML.parse()))
may result in different order- Example:
<a><b/><c/><b/></a>
will result in<a><b/><b/><c/></a>
- This may or may not be acceptable depending on your use case
- Example:
Basic usage
import { parse } from "https://deno.land/x/xml/mod.ts";
console.log(parse(`
<root>
<text>hello</text>
<array>world</array>
<array>monde</array>
<array>δΈη</array>
<array>π</array>
<number>42</number>
<boolean>true</boolean>
<complex attribute="value">content</complex>
</root>
`));
/*
Same nodes are grouped into arrays, while numbers and booleans are auto-parsed (can be disabled)
Nodes with attributes will not be flattened and you'll be able to access them with "@" prefix while
text nodes are available through "$" key
{
text:"hello",
array:["world", "monde", "δΈη", "π"],
number:42,
boolean:true,
complex:{
"@attribute":"value",
$:"content",
}
}
*/
import { stringify } from "https://deno.land/x/xml/mod.ts";
console.log(stringify({
root: {
text: "hello",
array: ["world", "monde", "δΈη", "π"],
number: 42,
boolean: true,
complex: {
"@attribute": "value",
$: "content",
},
},
}));
Revivers
By default, node contents will be converted to:
null
when empty, unlessemptyToNull = false
number
when matching finite numbers, unlessreviveNumbers = false
boolean
when matchingtrue
orfalse
(case insensitive), unlessreviveBooleans = false
XML entities (e.g. &
, &
, &
, β¦) will be unescaped
automatically.
You can also provide a custom reviver that will receive key
, value
and
tag
.