cxml icon indicating copy to clipboard operation
cxml copied to clipboard

Error when parsing a field which was not present in the xsd file

Open davidspiess opened this issue 7 years ago • 5 comments

If the parser (v.0.1.1) encounters a field which is not part of the xsd, it throws the following error

Unhandled rejection TypeError: Cannot read property 'proxy' of undefined
    at SAXStream.<anonymous> (/app/node_modules/cxml/dist/xml/Parser.js:160:24)
    at emitOne (events.js:116:13)
    at SAXStream.emit (events.js:211:7)
    at SAXParser.me._parser.(anonymous function) [as onclosetag] (/app/node_modules/sax/lib/sax.js:258:17)
    at emit (/app/node_modules/sax/lib/sax.js:624:35)
    at emitNode (/app/node_modules/sax/lib/sax.js:629:5)
    at closeTag (/app/node_modules/sax/lib/sax.js:889:7)
    at SAXParser.write (/app/node_modules/sax/lib/sax.js:1436:13)
    at SAXStream.write (/app/node_modules/sax/lib/sax.js:239:18)
    at Parser._parse (/app/node_modules/cxml/dist/xml/Parser.js:187:17)
    at /app/node_modules/cxml/dist/xml/Parser.js:53:26
    at Promise._execute (/app/node_modules/bluebird/js/release/debuggability.js:303:9)
    at Promise._resolveFromExecutor (/app/node_modules/bluebird/js/release/promise.js:483:18)
    at new Promise (/app/node_modules/bluebird/js/release/promise.js:79:10)
    at Parser.parse (/app/node_modules/cxml/dist/xml/Parser.js:52:17)
    at Object.<anonymous> (/app/src/index.ts:7:23)

If my xml provider adds a new field to their api my whole application breaks until i regenerate the xsd with cxsd.

davidspiess avatar May 04 '18 14:05 davidspiess

I noticed it's not possible to create a pull request for a specific commit or release so i forked the repository and fixed it for my project.

https://github.com/HGV/cxml/commit/7fad521b3d0f4a5993b2ce6e2b52ab87b8c45878

davidspiess avatar May 04 '18 15:05 davidspiess

@davidspiess Maybe here is not the best place to ask, but since you are using cxsd, do you have any doc on how to use it with cxml? I've tried to infer how to use them with their TS typings, but so far, no luck.

Thanks!

Ottunger avatar May 11 '18 05:05 Ottunger

I used the 0.1.1 version as there is documentation for that https://github.com/charto/cxml/tree/fce69086cd5f7ec476e0ff87d5a7f44b9879bd69

You have to pass the output of cxsd as second parameter to the parser.

import * as cxsd from 'cxsd/outputfiles';

const parser = new cxml.Parser();
parser.parse('<xml></xml>', cxsd.document);

davidspiess avatar May 11 '18 07:05 davidspiess

Thanks a lot :) Indeed .parse does not exist on the object according to TS.

So you're using a custom cxml, makes sense. Is it a fork of 0.1.1?

Ottunger avatar May 11 '18 07:05 Ottunger

Always glad to help! 😄 Yeah i created a fork of 0.1.1 because of the issue which i described above.

davidspiess avatar May 11 '18 08:05 davidspiess