Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

javascript parse xml

const txt = "<address> <street>Roble Ave</street> <mtfcc>S1400</mtfcc> </address>"

if (window.DOMParser){
    parser = new DOMParser();
    xmlDoc = parser.parseFromString(txt, "text/xml")
}
else // Internet Explorer
{
    xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
    xmlDoc.async = false;
    xmlDoc.loadXML(txt);
}
Comment

JavaScript parse XML to DOM

const xmlStr = '<q id="a"><span id="b">hey!</span></q>';
const parser = new DOMParser();
const doc = parser.parseFromString(xmlStr, "application/xml");
// print the name of the root element or error message
const errorNode = doc.querySelector("parsererror");
if (errorNode) {
  console.log("error while parsing");
} else {
  console.log(doc.documentElement.nodeName);
}
Comment

PREVIOUS NEXT
Code Example
Javascript :: node js throw error 
Javascript :: javascript classlist add 
Javascript :: jspdf attach image file 
Javascript :: javascript write all the prime numbers from 1 to 100 
Javascript :: javascript is number even or odd 
Javascript :: react native header height 
Javascript :: insert image into datatable 
Javascript :: jquery select attribute 
Javascript :: performance.now() javascript 
Javascript :: javascript append to array 
Javascript :: npx create-react-app current folder 
Javascript :: for htmlcollection javascript 
Javascript :: javascript get boolean if checkbox is checked 
Javascript :: error handling in express 
Javascript :: uploadgetfiletypefileextension 
Javascript :: prime number js 
Javascript :: jquery animation 
Javascript :: lodash convert object to array 
Javascript :: jQuery on right mouse click 
Javascript :: Reading Time with jquery 
Javascript :: get select2 selected value jquery 
Javascript :: vue js reload page 
Javascript :: delete cookies by domain javascript 
Javascript :: node mssql 
Javascript :: javascript remove certain element from array 
Javascript :: how to make a deep copy in javascript 
Javascript :: js url 
Javascript :: useeffect hook react 
Javascript :: nodejs current timestamp 
Javascript :: pyspark json multiline 
ADD CONTENT
Topic
Content
Source link
Name
4+2 =