JSFiddle - React, Tailwind, and code Playground
Babel + JSX
var xml = '<!--?xmlversion="1.0"encoding="UTF-8"?--><breakfast_menu><food><name>BelgianWaffles</name><price>$5.95</price><description >OurfamousBelgianWaffleswithplentyofrealmaplesyrup</description><calories>650</calories></food><food><name>FrenchToast</name><price>$4.50</price><description>Thickslicesmadefromourhomemadesourdoughbread</description><calories>600</calories></food><food><name>HomestyleBreakfast</name><price>$6.95</price><description>Twoeggs,baconorsausage,toast,andourever-popularhashbrowns</description><calories>950</calories></food></breakfast_menu>';
var code, index, regExp, tags, xml, isClose;
//xml = '<test aa="22"> <tag> <t>\n</t> </tag> </test>';
index = 246;
code = xml.slice(0, index);
tags = [];
regExp = /<(\/)?(\w+)?.*?/img;
code.replace(regExp, function(match, isClose, name) {
tags.push({
name: name,
isClose: !!isClose
});
});
console.log(tags);
console.log(code);