Aller au contenu
An 8-bit-style geometric illustration features three main icons: a computer file labeled with XML symbols, a basic document showing bracket shapes, and a square marked with curly braces to represent JSON. These icons are connected by one arrow to symbolize parsing. Nearby, a feed symbol and another arrow lead toward a plain geometric representation of a book, illustrating the conversion of RSS to plain text. The design uses five flat corporate colors, simple forms, no background, and avoids extra details, arranged within a small square format.

XML

AI generated translation.

La fonction def analysera automatiquement les fichiers XML et en extraira le texte.

def("DOCS", env.files) // contains some xml files
def("XML", env.files, { endsWith: ".xml" }) // only xml

La fonction globale XML.parse lit un fichier XML et le convertit en un objet JSON.

const res = XML.parse('<xml attr="1"><child /></xml>')

Les noms d’attributs sont précédés de ”@_”.

{
"xml": {
"@_attr": "1",
"child": {}
}
}

Vous pouvez utiliser XML.parse pour analyser un flux RSS en un objet.

const res = await fetch("https://dev.to/feed")
const { rss } = XML.parse(await res.text())
// channel -> item[] -> { title, description, ... }

Étant donné que les flux RSS renvoient généralement une description en HTML rendu, vous pouvez utiliser parsers.HTMLToText pour la convertir en texte brut.

const articles = items.map(({ title, description }) => ({
title,
description: parsers.HTMLToText(description)
}))