XML parser written in pure javascript for embedded environments

I am looking for a parser that can work in a javascript environment where there is no access to document , DOMParser or any other browser extension. The javascript application can work in browsers (IE, Firefox, Chrome, Safari ...) in node.js, but it is designed to run mainly built-in in V8 or in SpiderMonkey. The environment is spreading without the support of conventional XML parsers, and I cannot parse a string containing the correct XML from javascript.

All libraries that rely on browser extensions, such as DOMParser and ActiveXObject , fail with messages such as ReferenceError: DOMParser is not defined .

Access to the file system is not required (I need to parse from a string into a DOM-like structure).

+6
source share
2 answers

marknote is the right solution as stated here (thanks to Pekka 웃). The library uses XMLHttpRequest when loading from remote locations, but when analyzing from a string, it integrates a stand-alone XML parser written in javascript, which makes it suitable for use in built-in interpreters:

 var text="<note>"; text=text+"<content>whatever blablabla</content>"; text=text+"</note>"; var parser = new marknote.Parser(); var doc = parser.parse(text); native.log(doc.toString()); // show the formatted XML 
+4
source

Checkout jQuery.parseXML is the main XML parser.

-3
source

All Articles