Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add parseStringSync #422

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

mckramer
Copy link
Contributor

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

Create a sync version of parseString to API to permit
calling without a callback.

The current implemenation is sync due to underlying
implementation of SAX parser.

Examples:

```js
// Via root API
var result = xml2js.parseStringSync('< ... >', options)

// Via parser
var parser = new xml2js.Parser(options);
var result = parser.parseStringSync('< ... >');
```

See Leonidas-from-XIV#241 by @nobodyman
See Leonidas-from-XIV#319 by @mrparkers
@coveralls
Copy link

Coverage Status

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

1 similar comment
@coveralls
Copy link

Coverage Status

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

@tiaozi0912
Copy link

It would be nice if it could be merged

@RikkiGibson
Copy link

👍 to this, there should be no I/O happening in a function called parseString and so see no reason for it to be asynchronous

@lacroixthomas
Copy link

+1

@maitriyogin
Copy link

any ideas when this can be merged?

@julia-suarez-deel
Copy link

Please merge this..

@1mike12
Copy link

1mike12 commented May 25, 2019

lol why would this not be merged?

@fkirc
Copy link

fkirc commented Oct 20, 2020

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.

@ErrorBot1122
Copy link

@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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

10 participants