charto / cxml

Advanced schema-aware streaming XML parser
MIT License
45 stars 33 forks source link

use cxml in browser #5

Open sunnyawake5 opened 8 years ago

sunnyawake5 commented 8 years ago

can cxml used in browser env?

thanks.

jjrv commented 7 years ago

Support should be coming this year, but it may still be some months away with so many ongoing projects. It will use the browser's native XML parsing, and process the result to use JavaScript objects matching the schema: if the schema allows several child elements of the same type, then even a single such child will be in an array, and placeholders will be added to the object prototypes for required elements so you code can rely on them being present.

owennewo commented 7 years ago

I've just started using cxml in an angular4/typescript app. It works. Took me a while to get it working - the system-config.ts requires a long list of map and packages declaration to get the dependent modules loaded. I expect there was an easier way but I'm new to javascript module loading.

My browser loads the angular4 app from node/lite-server then it loads a remote musicxml file and then uses cxml.parser.parse(xml, musicxml.document). The musicxml.document was created using cxsd.

@jjrv - does the work you are intending to do mean that you won't have so many node dependencies?

jjrv commented 7 years ago

@owennewo Congratulations on getting it working!

Currently I'm working on the rewrite branch, a much faster implementation with nbind as the only dependency. The XML parser core will be a native binary on Node.js. It's mostly ready now. A precompiled asm.js version with no dependencies will be provided in case a C++ compiler is not installed. I expect the native binary version to be overall the fastest XML parser available for JavaScript.

I'll do some testing but it seems likely to outperform using the browser's native parsing, since the browser creates a DOM tree that then gets thrown away. If the browsers' own parser runs faster after all, I'll use that.

Current master branch of cxml depends on sax which uses Node.js internal libraries that need shims for browsers as provided by SystemJS, Browserify and such. I'll get rid of that library to avoid the issue.

Ultimately a single .js file will be provided for browsers, so it can be simply included with a script tag if not using any JS loader.