xml-twig 1.2.93 → 1.2.94

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/twig.js +10 -6
package/package.json CHANGED
@@ -5,7 +5,7 @@
5
5
  },
6
6
  "name": "xml-twig",
7
7
  "description": "Node module for processing huge XML documents in tree mode",
8
- "version": "1.2.93",
8
+ "version": "1.2.94",
9
9
  "main": "twig.js",
10
10
  "directories": {
11
11
  "doc": "doc"
package/twig.js CHANGED
@@ -205,14 +205,15 @@ function createParser(handler, options = {}) {
205
205
  });
206
206
 
207
207
  parser.on("attribute", function (attr) {
208
- current.attribute(attr.name, attr.value);
209
- if ((attr.uri ?? '') !== '' && attr.local !== undefined) {
208
+ if (options.xmlns && (attr.uri ?? '') !== '' && attr.local !== undefined) {
210
209
  namespaces[attr.local] = attr.uri;
211
210
  Object.defineProperty(current, 'namespace', {
212
211
  value: { local: attr.local, uri: attr.uri },
213
212
  writable: false,
214
213
  enumerable: true
215
214
  });
215
+ } else {
216
+ current.attribute(attr.name, attr.value);
216
217
  }
217
218
  });
218
219
  parser.on("cdata", function (str) {
@@ -239,13 +240,18 @@ function createParser(handler, options = {}) {
239
240
  closeEvent = "endElement";
240
241
 
241
242
  parser.on("startElement", function (name, attrs) {
243
+ let attr = {};
244
+ if (options.xmlns) {
245
+ for (let key of Object.keys(attrs).filter(x => !x.startsWith('xmlns:')))
246
+ attr[key] = attrs[key];
247
+ }
242
248
  if (tree === undefined) {
243
- tree = new Twig(name, current, attrs);
249
+ tree = new Twig(name, current, options.xmlns ? attr : attrs);
244
250
  } else {
245
251
  if (current.isRoot && current.name === undefined) {
246
252
  current.setRoot(name);
247
253
  } else {
248
- let elt = new Twig(name, current, attrs);
254
+ let elt = new Twig(name, current, options.xmlns ? attr : attrs);
249
255
  if (options.partial) {
250
256
  for (let hndl of Array.isArray(handler) ? handler : [handler]) {
251
257
  if (typeof hndl.tag === 'string' && name === hndl.tag) {
@@ -262,8 +268,6 @@ function createParser(handler, options = {}) {
262
268
  }
263
269
  }
264
270
  }
265
- for (let attr in attrs)
266
- current.attribute(attr, attrs[attr]);
267
271
  if (options.xmlns) {
268
272
  for (let key of Object.keys(attrs).filter(x => x.startsWith('xmlns:')))
269
273
  namespaces[key.split(':')[1]] = attrs[key];