node-xml2js icon indicating copy to clipboard operation
node-xml2js copied to clipboard

Add parseStringSync

Open mckramer opened this issue 6 years ago • 10 comments

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:

  1. Allows user to specify options to global parseStringSync method as requested here
  2. Add additional tests for the parser + global version of the method
  3. 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

mckramer avatar Feb 13 '18 02:02 mckramer

Coverage Status

Coverage increased (+0.1%) to 97.746% when pulling c7df57cd647083a9a100c42c21466e6838c5face on mckramer:parse-string-sync into f8a4d694366ef62b32461bf6a3d58c18b4c28255 on Leonidas-from-XIV:master.

coveralls avatar Mar 12 '18 00:03 coveralls

Coverage Status

Coverage increased (+0.1%) to 97.746% when pulling c7df57cd647083a9a100c42c21466e6838c5face on mckramer:parse-string-sync into f8a4d694366ef62b32461bf6a3d58c18b4c28255 on Leonidas-from-XIV:master.

coveralls avatar Mar 12 '18 00:03 coveralls

It would be nice if it could be merged

tiaozi0912 avatar Apr 03 '18 11:04 tiaozi0912

:+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

RikkiGibson avatar Apr 06 '18 00:04 RikkiGibson

+1

lacroixthomas avatar Jun 26 '18 17:06 lacroixthomas

any ideas when this can be merged?

maitriyogin avatar Jan 14 '19 12:01 maitriyogin

Please merge this..

julia-suarez-deel avatar May 20 '19 22:05 julia-suarez-deel

lol why would this not be merged?

1mike12 avatar May 25 '19 02:05 1mike12

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.

fkirc avatar Oct 20 '20 16:10 fkirc

@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

ErrorBot1122 avatar Sep 04 '21 03:09 ErrorBot1122