Skip to main content
Module

x/xml/mod.ts>parse

๐Ÿ“‘ A XML parser/stringifier for Deno written in typescript and with no dependencies
Go to Latest
function parse
import { parse } from "https://deno.land/x/xml@4.0.0/mod.ts";

XML parser

Parse a string or a Flux stream into a document.

Parsed attributes will be prefixed with @, while comments will be stored in #comment property and content in #text. If a node does not possess any attribute or comments, then it will be flattened into its text content for convenience.

ParserOptions can be used to customize the parser behavior.

Examples

Example 1

import { parse } from "./parse.ts"

console.log(parse(
`
  <root>
    <!-- This is a comment -->
    <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>
`,
  { reviveNumbers: true, reviveBooleans: true },
))

Parameters

content: string | Flux
optional
options: ParserOptions

Returns

document