Coder Social home page Coder Social logo

cmrigney / fast-xml2js Goto Github PK

View Code? Open in Web Editor NEW
12.0 12.0 3.0 58 KB

In-place replacement for xml2js parseString. This is about 20x faster and makes use of the rapidxml C++ library.

Home Page: https://www.npmjs.com/package/fast-xml2js

License: MIT License

Python 0.28% C++ 56.20% HTML 43.29% JavaScript 0.23%
fast json xml xml2js

fast-xml2js's People

Contributors

cmrigney avatar jbrw1984 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

fast-xml2js's Issues

Invalid XML kills process

When fast-xml2js is given invalid XML syntax, it kills the process, rather than catching the error and logging it.

Invalid XML example:

<UserName>asdf</UserName/>

Usage example:

import { parseString } from 'fast-xml2js'
...
export const parseXML = (str, opts) => {
    return new Promise((resolve, reject) => {
        parseString(str, (err, rst) => {
            if (err) {
                logger.error('Error parsing XML file')
                reject(err)
            } else {
                resolve(rst)
            }
        })
    })
}

When xml2js encounters the same syntax, it throws the following error:

Error: Invalid tagname in closing tag
Line: 2
Column: 37
Char: /

Installing in docker is broken

> docker pull node
> docker run -it node /bin/bash
root@4a251ed35176:/# mkdir test
root@4a251ed35176:/# cd test
root@4a251ed35176:/test# npm init -y
root@4a251ed35176:/test# npm install --save fast-xml2js
npm info it worked if it ends with ok
npm info using [email protected]
npm info using [email protected]
npm info attempt registry request try #1 at 9:36:57 PM
npm http request GET https://registry.npmjs.org/fast-xml2js
npm http 304 https://registry.npmjs.org/fast-xml2js
npm info addNameTag [ 'fast-xml2js', 'latest' ]
npm info lifecycle [email protected]~preinstall: [email protected]
npm WARN lifecycle [email protected]~preinstall: cannot run in wd %s %s (wd=%s) [email protected] node-gyp configure && node-gyp build /test/node_modules/.staging/fast-xml2js-5c4308bb
npm info linkStuff [email protected]
npm info lifecycle [email protected]~install: [email protected]
npm info lifecycle [email protected]~postinstall: [email protected]
[email protected] /test
`-- [email protected] 

npm WARN [email protected] No description
npm WARN [email protected] No repository field.
npm info ok
root@4a251ed35176:/test# node -r fast-xml2js -e 'true'   
module.js:457
    throw err;
    ^

Error: Cannot find module './fast-xml2js/fast-xml2js.node'
    at Function.Module._resolveFilename (module.js:455:15)
    at Function.Module._load (module.js:403:25)
    at Module.require (module.js:483:17)
    at require (internal/module.js:20:19)
    at Object.<anonymous> (/test/node_modules/fast-xml2js/index.js:1:80)
    at Module._compile (module.js:556:32)
    at Object.Module._extensions..js (module.js:565:10)
    at Module.load (module.js:473:32)
    at tryModuleLoad (module.js:432:12)
    at Function.Module._load (module.js:424:3)

This has something to do with the way node-gyp is set up with this package: http://stackoverflow.com/a/19132229/403571

It seems the workaround is npm install --unsafe-perm.

The problem does not exist in other native modules.

Doesn't compile anymore

Hi,

With the latest node.js this doesn't compile anymore.
It looks like some argument count has changed.

make: Entering directory '/src/tor/node_modules/fast-xml2js/build'
  CXX(target) Release/obj.target/fast-xml2js/fast-xml2js.o
../fast-xml2js.cpp: In function 'void fastxml2js::ParseString(const v8::FunctionCallbackInfo<v8::Value>&)':
../fast-xml2js.cpp:46:46: warning: 'v8::Local<v8::String> v8::Value::ToString() const' is deprecated: Use maybe version [-Wdeprecated-declarations]
   String::Utf8Value param1(args[0]->ToString());
                                              ^
In file included from /root/.node-gyp/11.11.0/include/node/node.h:63:0,
                 from ../fast-xml2js.cpp:2:
/root/.node-gyp/11.11.0/include/node/v8.h:10251:15: note: declared here
 Local<String> Value::ToString() const {
               ^~~~~
../fast-xml2js.cpp:46:47: warning: 'v8::String::Utf8Value::Utf8Value(v8::Local<v8::Value>)' is deprecated: Use Isolate version [-Wdeprecated-declarations]
   String::Utf8Value param1(args[0]->ToString());
                                               ^
In file included from /root/.node-gyp/11.11.0/include/node/v8.h:26:0,
                 from /root/.node-gyp/11.11.0/include/node/node.h:63,
                 from ../fast-xml2js.cpp:2:
/root/.node-gyp/11.11.0/include/node/v8.h:2992:28: note: declared here
                   explicit Utf8Value(Local<v8::Value> obj));
                            ^
/root/.node-gyp/11.11.0/include/node/v8config.h:326:3: note: in definition of macro 'V8_DEPRECATED'
   declarator __attribute__((deprecated(message)))
   ^~~~~~~~~~
../fast-xml2js.cpp:90:76: error: no matching function for call to 'v8::Object::HasOwnProperty(v8::Local<v8::String>)'
           if(obj->HasOwnProperty(String::NewFromUtf8(isolate, node->name())))
                                                                            ^
In file included from /root/.node-gyp/11.11.0/include/node/node.h:63:0,
                 from ../fast-xml2js.cpp:2:
/root/.node-gyp/11.11.0/include/node/v8.h:3617:37: note: candidate: v8::Maybe<bool> v8::Object::HasOwnProperty(v8::Local<v8::Context>, v8::Local<v8::Name>)
   V8_WARN_UNUSED_RESULT Maybe<bool> HasOwnProperty(Local<Context> context,
                                     ^~~~~~~~~~~~~~
/root/.node-gyp/11.11.0/include/node/v8.h:3617:37: note:   candidate expects 2 arguments, 1 provided
/root/.node-gyp/11.11.0/include/node/v8.h:3619:37: note: candidate: v8::Maybe<bool> v8::Object::HasOwnProperty(v8::Local<v8::Context>, uint32_t)
   V8_WARN_UNUSED_RESULT Maybe<bool> HasOwnProperty(Local<Context> context,
                                     ^~~~~~~~~~~~~~
/root/.node-gyp/11.11.0/include/node/v8.h:3619:37: note:   candidate expects 2 arguments, 1 provided
../fast-xml2js.cpp:113:76: error: no matching function for call to 'v8::Object::HasOwnProperty(v8::Local<v8::String>)'
           if(obj->HasOwnProperty(String::NewFromUtf8(isolate, node->name())))
                                                                            ^
In file included from /root/.node-gyp/11.11.0/include/node/node.h:63:0,
                 from ../fast-xml2js.cpp:2:
/root/.node-gyp/11.11.0/include/node/v8.h:3617:37: note: candidate: v8::Maybe<bool> v8::Object::HasOwnProperty(v8::Local<v8::Context>, v8::Local<v8::Name>)
   V8_WARN_UNUSED_RESULT Maybe<bool> HasOwnProperty(Local<Context> context,
                                     ^~~~~~~~~~~~~~
/root/.node-gyp/11.11.0/include/node/v8.h:3617:37: note:   candidate expects 2 arguments, 1 provided
/root/.node-gyp/11.11.0/include/node/v8.h:3619:37: note: candidate: v8::Maybe<bool> v8::Object::HasOwnProperty(v8::Local<v8::Context>, uint32_t)
   V8_WARN_UNUSED_RESULT Maybe<bool> HasOwnProperty(Local<Context> context,
                                     ^~~~~~~~~~~~~~
/root/.node-gyp/11.11.0/include/node/v8.h:3619:37: note:   candidate expects 2 arguments, 1 provided
make: *** [fast-xml2js.target.mk:97: Release/obj.target/fast-xml2js/fast-xml2js.o] Error 1
make: Leaving directory '/src/tor/node_modules/fast-xml2js/build'

Cheers,
Mark

Nice project

Just wanna thank you for publishing this. I do like the idea of xml2js but the performance is terrible. I'm gonna do some testing and let you know how it holds up.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.