Skip to content

Commit 245132d

Browse files
committed
Merge branch 'main' of github.com:steelcheetah/node-xml-toolkit into _type
2 parents 0ade363 + f95ea90 commit 245132d

File tree

6 files changed

+30
-6
lines changed

6 files changed

+30
-6
lines changed

__tests__/XMLMarshaller.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -272,7 +272,7 @@ test ('20319', async () => {
272272
MessageData: {
273273
AppData: {
274274
data: {
275-
[Symbol.for ('type')]: 'getOrganizationsByEasRequest',
275+
[Symbol.for ('type')]: 'GetOrganizationsByEasRequest',
276276
eas: 123456,
277277
countRecord: 1,
278278
page: 1
@@ -282,6 +282,8 @@ test ('20319', async () => {
282282
}
283283
}
284284

285+
expect (xs.stringify (data)).toMatch (/xsi:type="ns\d*:GetOrganizationsByEasRequest"/)
286+
285287
expect (xs.stringify (data)).toMatch ('eas>123456<')
286288

287289
})

__tests__/XMLSchemata.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
const path = require('path')
2+
const { XMLSchemata } = require('../')
3+
4+
test('cyclic import', async () => {
5+
const xsdPath = path.join(__dirname, '..', '__data__', '30213','RequestEGRN_v026.xsd')
6+
7+
const schemata = await new Promise((resolve, reject) => {
8+
XMLSchemata.fromFile(xsdPath)
9+
.then(s => resolve(s))
10+
.catch(e => reject(e))
11+
})
12+
13+
expect(schemata).toBeDefined()
14+
expect(schemata.size).toBeGreaterThan(0)
15+
})

lib/XMLMarshaller.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ const XMLMarshaller = class {
111111

112112
if (data && data [XSI_TYPE]) {
113113
let d = {}; for (let k in data) d [k] = data [k]
114-
this.appendElementBody (this.schema.get (data [XSI_TYPE]), d)
114+
this.appendContent (this.schema.getType (data [XSI_TYPE]), d)
115115
}
116116

117117
if (type) return this.appendContent (this.xs.getType (type), data)
@@ -145,7 +145,8 @@ const XMLMarshaller = class {
145145
this.xs.getAttributeSimpleType (node).stringify (v)
146146
)
147147

148-
case 'extension':
148+
case 'extension':
149+
case 'restriction':
149150
this.appendAttributes (this.xs.getType (attributes.base), data)
150151

151152
default:

lib/XMLSchemata.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ const XMLSchemata = class extends Map {
2727
new XMLSchemaXml (this)
2828
new XMLSchemaBuiltIn (this)
2929

30+
this.loadedFiles = new Set()
31+
3032
this.addFile (fn)
3133

3234
}
@@ -159,6 +161,10 @@ const XMLSchemata = class extends Map {
159161

160162
addFile (fn, options = {}) {
161163

164+
if (this.loadedFiles.has (fn)) return
165+
166+
this.loadedFiles.add (fn)
167+
162168
options.dirname = path.dirname (fn)
163169

164170
const document = this.parser.process (fs.readFileSync (fn, 'utf-8'))

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "xml-toolkit",
3-
"version": "1.0.55",
3+
"version": "1.0.58",
44
"description": "XML parser, marshaller, SOAP adapter",
55
"main": "index.js",
66
"files": [

0 commit comments

Comments
 (0)