Published
Edited
Jan 19, 2022
1 fork
Insert cell
Insert cell
// sample xml file from:
// https://docs.microsoft.com/en-us/previous-versions/windows/desktop/ms762271(v=vs.85)
xml = FileAttachment("books.xml").text()
Insert cell
Insert cell
import {xmlToJSON} from "@visnup/xml-to-json"
Insert cell
Insert cell
books = xmlToJSON(xml).catalog.book
Insert cell
Insert cell
booksByTitle = new Map(books.map(d => [d.title, d]))
Insert cell
Insert cell
booksByTitle.get("Midnight Rain")
Insert cell
Insert cell
viewof book = Inputs.radio(booksByTitle, {label: "Book", value: books[0]})
Insert cell
Insert cell
book
Insert cell
Insert cell
xml2 = FileAttachment("xml@1.txt").text()
Insert cell
Insert cell
data = xmlToJSON(xml2)
Insert cell
Insert cell
data.WMS_Capabilities.Capability.Layer.Layer.Layer.map(d => d.Name)
Insert cell
Insert cell
xmlJS = require('https://bundle.run/xml-js@1.6.11')
Insert cell
data2 = JSON.parse(xmlJS.xml2json(xml2))
Insert cell
Insert cell
data2.elements[0].elements
.find((d) => d.name === "Capability")
.elements.find((d) => d.name === "Layer")
.elements.find((d) => d.name === "Layer")
.elements.filter((d) => d.name === "Layer")
.map((d) => d.elements.find((d) => d.name === "Title").elements[0].text)
Insert cell

Purpose-built for displays of data

Observable is your go-to platform for exploring data and creating expressive data visualizations. Use reactive JavaScript notebooks for prototyping and a collaborative canvas for visual data exploration and dashboard creation.
Learn more