xml-toolkit 1.0.53 → 1.0.55

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.
@@ -2,6 +2,8 @@ const assert = require ('assert')
2
2
  const NamespacePrefixesMap = require ('./NamespacePrefixesMap.js')
3
3
  const XMLPrinter = require ('./XMLPrinter.js')
4
4
 
5
+ const XSI_TYPE = Symbol.for ('type')
6
+
5
7
  const XMLMarshaller = class {
6
8
 
7
9
  constructor (xs, localName, namespaceURI, printerOptions = {}) {
@@ -74,6 +76,15 @@ const XMLMarshaller = class {
74
76
  this.isNsDumped = true
75
77
 
76
78
  }
79
+
80
+ if (data [XSI_TYPE]) {
81
+
82
+ let {targetNamespace} = this.xs.getSchemaByLocalName(data [XSI_TYPE])
83
+
84
+ this.printer
85
+ .writeAttribute ('xmlns:xsi', 'http://www.w3.org/2001/XMLSchema-instance')
86
+ .writeAttribute ('xsi:type', this.ns.QName (data [XSI_TYPE], targetNamespace))
87
+ }
77
88
 
78
89
  this.appendAttributes (node, data)
79
90
 
@@ -98,6 +109,11 @@ const XMLMarshaller = class {
98
109
 
99
110
  const {attributes: {type}, children} = node
100
111
 
112
+ if (data [XSI_TYPE]) {
113
+ let d = {}; for (let k in data) d [k] = data [k]
114
+ this.appendElementBody (this.schema.get (data [XSI_TYPE]), d)
115
+ }
116
+
101
117
  if (type) return this.appendContent (this.xs.getType (type), data)
102
118
 
103
119
  for (const i of children) this.appendContent (i, data)
@@ -111,7 +127,7 @@ const XMLMarshaller = class {
111
127
  if (ref) return this.appendAttributes (this.xs.getByReference (ref), data)
112
128
 
113
129
  const {type} = node.attributes; if (type) this.appendAttributes (this.xs.getType (type), data)
114
-
130
+
115
131
  switch (localName) {
116
132
 
117
133
  case 'sequence':
package/lib/XMLReader.js CHANGED
@@ -211,8 +211,13 @@ const XMLReader = class extends Transform {
211
211
  case SAXEvent.TYPES.CHARACTERS:
212
212
  case SAXEvent.TYPES.CDATA:
213
213
 
214
- this.text += e.text
215
- return callback ()
214
+ try {
215
+ this.text += e.text
216
+ return callback ()
217
+ }
218
+ catch (error) {
219
+ return callback (error)
220
+ }
216
221
 
217
222
  default:
218
223
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "xml-toolkit",
3
- "version": "1.0.53",
3
+ "version": "1.0.55",
4
4
  "description": "XML parser, marshaller, SOAP adapter",
5
5
  "main": "index.js",
6
6
  "files": [