node-xml2js
node-xml2js copied to clipboard
Add parseStringSync
Create a sync version of parseString to API to permit calling without a callback. The current implementation is sync due to underlying implementation of SAX parser.
This is a rebased version of #319 by @mrparkers which in turn was an add-on to #241 by @nobodyman. In addition to those changes, this PR:
- Allows user to specify options to global parseStringSync method as requested here
- Add additional tests for the parser + global version of the method
- Adds info to README to describe usage of new methods
Examples:
// Via root API
var result = xml2js.parseStringSync('< ... >', options)
// Via parser
var parser = new xml2js.Parser(options);
var result = parser.parseStringSync('< ... >');
See #241 by @nobodyman See #319 by @mrparkers
Coverage increased (+0.1%) to 97.746% when pulling c7df57cd647083a9a100c42c21466e6838c5face on mckramer:parse-string-sync into f8a4d694366ef62b32461bf6a3d58c18b4c28255 on Leonidas-from-XIV:master.
Coverage increased (+0.1%) to 97.746% when pulling c7df57cd647083a9a100c42c21466e6838c5face on mckramer:parse-string-sync into f8a4d694366ef62b32461bf6a3d58c18b4c28255 on Leonidas-from-XIV:master.
It would be nice if it could be merged
:+1: to this, there should be no I/O happening in a function called parseString
and so see no reason for it to be asynchronous
+1
any ideas when this can be merged?
Please merge this..
lol why would this not be merged?
For a function that is called parseStringSomething
, it is strange that there doesn't exist a synchronous version.
After all, all the parsing logic should be naturally synchronous.
Nevertheless, I hope that volunteers will get permission to continue maintenance.
@Leonidas-from-XIV Plz merge this... I need sync function because I'm trying converting the parser to "sync" new Parser({async: true})
and parsing returns this mess!!!
{
comment: '',
sgmlDecl: '',
textNode: '',
tagName: '',
doctype: '',
procInstName: '',
procInstBody: '',
entity: '',
attribName: '',
attribValue: '',
cdata: '',
script: '',
c: '',
q: '',
bufferCheckPosition: 65536,
opt: { trim: false, normalize: false, xmlns: false, lowercase: undefined },
looseCase: 'toUpperCase',
tags: [],
sawRoot: false,
closedRoot: false,
closed: false,
error: null,
tag: null,
strict: true,
noscript: true,
state: 0,
strictEntities: undefined,
ENTITIES: {},
attribList: [],
trackPosition: true,
column: 0,
line: 0,
position: 0,
errThrown: false,
onerror: [Function],
onend: [Function],
ended: false,
onopentag: [Function],
onclosetag: [Function],
ontext: [Function],
oncdata: [Function]
}
my repo: https://github.com/ErrorBot1122/Roblox-Parser