Back to packages list

Vals using fast-xml-parser

Description from the NPM package:
Validate XML, Parse XML, Build XML without C/C++ based libraries
1
2
3
4
5
6
7
8
9
10
11
import { fetchText } from "https://esm.town/v/mgruel/fetchText";
export const fetchAndParseXML = async <T extends any = any>(
url: string | URL,
options?: RequestInit,
): Promise<T> => {
const { XMLParser } = await import("npm:fast-xml-parser");
const parser = new XMLParser();
const xmlString = await fetchText(url, options);
return parser.parse(xmlString) as T;
};
1
2
3
4
5
export async function parseXML(xml) {
const { XMLParser } = await import("https://esm.sh/fast-xml-parser@4.1.2");
const parser = new XMLParser();
return parser.parse(xml);
}
1
2
3
4
5
6
7
8
9
10
11
import { fetch } from "https://esm.town/v/std/fetch";
export async function fetchRssParser(rssUrl) {
// fetch the rss xml
const rssResult = await fetch(rssUrl).then((res) => res.text());
// parse xml to object
const { XMLParser } = await import("npm:fast-xml-parser");
const parser = new XMLParser();
let jObj = parser.parse(rssResult);
return jObj;
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
export const parseXMLFastXML = async (
xml: string
): Promise<Record<string, any>> => {
// Load the external dependency
const { XMLParser } = await import("npm:fast-xml-parser");
// Set some default options so we don't ignore attributes
const xmlOptions = {
ignoreAttributes: false,
attributeNamePrefix: "@_",
ignoreDeclaration: true,
};
// Setup the parser with options
const parser = new XMLParser(xmlOptions);
return parser.parse(xml);
};
1
Next