How to use the xml.XML.parse function in xml

To help you get started, we’ve selected a few xml examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github Moddable-OpenSource / moddable / examples / network / http / httpgetxml / main.js View on Github external
request.callback = function(message, value)
{
	if (Request.responseComplete == message) {
		let root = XML.parse(value);

		let cityElement = root.elements.find(element => "city" == element.name);
		let valueAttribute = cityElement.attributes.find(attribute => "name" == attribute.name);
		let city = valueAttribute.value;

		let temperatureElement = root.elements.find(element => "temperature" == element.name);
		valueAttribute = temperatureElement.attributes.find(attribute => "value" == attribute.name);
		let temperature = Number.parseFloat(valueAttribute.value);

		let weatherElement = root.elements.find(element => "weather" == element.name);
		valueAttribute = weatherElement.attributes.find(attribute => "value" == attribute.name);
		let weather = valueAttribute.value;

		trace(`The temperature in ${city} is ${temperature} F.\n`);
		trace(`The weather condition is ${weather}.\n`);
	}