@abapify/ts-xsd 0.4.1 → 0.4.4
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.
- package/README.md +143 -211
- package/dist/codegen/cli.d.mts +1 -1
- package/dist/codegen/cli.mjs +2 -2
- package/dist/codegen/cli.mjs.map +1 -1
- package/dist/{generate-DnX2dJZe.mjs → generate-BsE7j6DV.mjs} +5 -5
- package/dist/generate-BsE7j6DV.mjs.map +1 -0
- package/dist/generators/index.d.mts +1 -2
- package/dist/generators/index.d.mts.map +1 -1
- package/dist/generators/index.mjs +7 -7
- package/dist/generators/index.mjs.map +1 -1
- package/dist/index.d.mts +60 -40
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +998 -51
- package/dist/index.mjs.map +1 -1
- package/dist/{runner-C4_p2y5e.d.mts → runner-D1RCU_go.d.mts} +6 -3
- package/dist/runner-D1RCU_go.d.mts.map +1 -0
- package/dist/{runner-CRhT3smd.mjs → runner-DX40fZp_.mjs} +49 -852
- package/dist/runner-DX40fZp_.mjs.map +1 -0
- package/dist/{types-CtrpGRyM.mjs → types-DqeG5gw1.mjs} +42 -16
- package/dist/types-DqeG5gw1.mjs.map +1 -0
- package/package.json +2 -2
- package/dist/generate-DnX2dJZe.mjs.map +0 -1
- package/dist/runner-C4_p2y5e.d.mts.map +0 -1
- package/dist/runner-CRhT3smd.mjs.map +0 -1
- package/dist/types-CtrpGRyM.mjs.map +0 -1
package/dist/index.mjs
CHANGED
|
@@ -1,8 +1,812 @@
|
|
|
1
|
-
import { _ as
|
|
2
|
-
import { n as generateSchemaLiteral, t as generateSchemaFile } from "./generate-
|
|
3
|
-
import { n as deriveRootTypeName, r as generateInterfaces, t as defineConfig } from "./types-
|
|
1
|
+
import { _ as getLocalName, a as loadAndLinkSchema, c as getSubstitutes, d as SchemaTraverser, f as resolveSchemaTypes, g as getChildElements, h as getAttributeValue, i as linkSchema, l as resolveSchema, m as getAllChildElements, n as createSchemaLoader, o as loadSchema, p as parseXsd, r as defaultLoader, s as parseSchemaContent, t as runCodegen, u as SchemaResolver, v as getTextContent } from "./runner-DX40fZp_.mjs";
|
|
2
|
+
import { n as generateSchemaLiteral, t as generateSchemaFile } from "./generate-BsE7j6DV.mjs";
|
|
3
|
+
import { n as deriveRootTypeName, r as generateInterfaces, t as defineConfig } from "./types-DqeG5gw1.mjs";
|
|
4
4
|
import { DOMImplementation, DOMParser, XMLSerializer } from "@xmldom/xmldom";
|
|
5
5
|
|
|
6
|
+
//#region src/xsd/build.ts
|
|
7
|
+
/**
|
|
8
|
+
* Build an XSD string from a typed Schema object
|
|
9
|
+
*/
|
|
10
|
+
function buildXsd(schema, options = {}) {
|
|
11
|
+
const prefix = options.prefix ?? "xs";
|
|
12
|
+
const pretty = options.pretty ?? true;
|
|
13
|
+
const ctx = {
|
|
14
|
+
prefix,
|
|
15
|
+
pretty,
|
|
16
|
+
indent: options.indent ?? " ",
|
|
17
|
+
level: 0
|
|
18
|
+
};
|
|
19
|
+
const lines = [];
|
|
20
|
+
lines.push("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
|
|
21
|
+
lines.push(buildSchema(schema, ctx));
|
|
22
|
+
return lines.join(pretty ? "\n" : "");
|
|
23
|
+
}
|
|
24
|
+
function buildSchema(schema, ctx) {
|
|
25
|
+
const attrs = [];
|
|
26
|
+
if (schema.$xmlns) for (const [prefix, uri] of Object.entries(schema.$xmlns)) if (prefix === "") attrs.push(`xmlns="${uri}"`);
|
|
27
|
+
else attrs.push(`xmlns:${prefix}="${uri}"`);
|
|
28
|
+
addAttr(attrs, "id", schema.id);
|
|
29
|
+
addAttr(attrs, "targetNamespace", schema.targetNamespace);
|
|
30
|
+
addAttr(attrs, "version", schema.version);
|
|
31
|
+
addAttr(attrs, "finalDefault", schema.finalDefault);
|
|
32
|
+
addAttr(attrs, "blockDefault", schema.blockDefault);
|
|
33
|
+
addAttr(attrs, "attributeFormDefault", schema.attributeFormDefault);
|
|
34
|
+
addAttr(attrs, "elementFormDefault", schema.elementFormDefault);
|
|
35
|
+
addAttr(attrs, "defaultAttributes", schema.defaultAttributes);
|
|
36
|
+
addAttr(attrs, "xpathDefaultNamespace", schema.xpathDefaultNamespace);
|
|
37
|
+
addAttr(attrs, "xml:lang", schema["xml:lang"]);
|
|
38
|
+
const children = [];
|
|
39
|
+
const childCtx = {
|
|
40
|
+
...ctx,
|
|
41
|
+
level: ctx.level + 1
|
|
42
|
+
};
|
|
43
|
+
if (schema.annotation) for (const ann of schema.annotation) children.push(buildAnnotation(ann, childCtx));
|
|
44
|
+
if (schema.include) for (const inc of schema.include) children.push(buildInclude(inc, childCtx));
|
|
45
|
+
if (schema.import) for (const imp of schema.import) children.push(buildImport(imp, childCtx));
|
|
46
|
+
if (schema.redefine) for (const red of schema.redefine) children.push(buildRedefine(red, childCtx));
|
|
47
|
+
if (schema.override) for (const ovr of schema.override) children.push(buildOverride(ovr, childCtx));
|
|
48
|
+
if (schema.defaultOpenContent) children.push(buildDefaultOpenContent(schema.defaultOpenContent, childCtx));
|
|
49
|
+
if (schema.simpleType && Array.isArray(schema.simpleType)) for (const st of schema.simpleType) children.push(buildTopLevelSimpleType(st, childCtx));
|
|
50
|
+
if (schema.complexType && Array.isArray(schema.complexType)) for (const ct of schema.complexType) children.push(buildTopLevelComplexType(ct, childCtx));
|
|
51
|
+
if (schema.group) for (const grp of schema.group) children.push(buildNamedGroup(grp, childCtx));
|
|
52
|
+
if (schema.attributeGroup) for (const ag of schema.attributeGroup) children.push(buildNamedAttributeGroup(ag, childCtx));
|
|
53
|
+
if (schema.element) for (const el of schema.element) children.push(buildTopLevelElement(el, childCtx));
|
|
54
|
+
if (schema.attribute) for (const attr of schema.attribute) children.push(buildTopLevelAttribute(attr, childCtx));
|
|
55
|
+
if (schema.notation) for (const not of schema.notation) children.push(buildNotation(not, childCtx));
|
|
56
|
+
return buildElement$1(`${ctx.prefix}:schema`, attrs, children, ctx);
|
|
57
|
+
}
|
|
58
|
+
function buildAnnotation(ann, ctx) {
|
|
59
|
+
const attrs = [];
|
|
60
|
+
addAttr(attrs, "id", ann.id);
|
|
61
|
+
const children = [];
|
|
62
|
+
const childCtx = {
|
|
63
|
+
...ctx,
|
|
64
|
+
level: ctx.level + 1
|
|
65
|
+
};
|
|
66
|
+
if (ann.appinfo) for (const ai of ann.appinfo) children.push(buildAppinfo(ai, childCtx));
|
|
67
|
+
if (ann.documentation) for (const doc of ann.documentation) children.push(buildDocumentation(doc, childCtx));
|
|
68
|
+
return buildElement$1(`${ctx.prefix}:annotation`, attrs, children, ctx);
|
|
69
|
+
}
|
|
70
|
+
function buildDocumentation(doc, ctx) {
|
|
71
|
+
const attrs = [];
|
|
72
|
+
addAttr(attrs, "source", doc.source);
|
|
73
|
+
addAttr(attrs, "xml:lang", doc["xml:lang"]);
|
|
74
|
+
if (doc._text) return buildElementWithText(`${ctx.prefix}:documentation`, attrs, doc._text, ctx);
|
|
75
|
+
return buildElement$1(`${ctx.prefix}:documentation`, attrs, [], ctx);
|
|
76
|
+
}
|
|
77
|
+
function buildAppinfo(ai, ctx) {
|
|
78
|
+
const attrs = [];
|
|
79
|
+
addAttr(attrs, "source", ai.source);
|
|
80
|
+
if (ai._text) return buildElementWithText(`${ctx.prefix}:appinfo`, attrs, ai._text, ctx);
|
|
81
|
+
return buildElement$1(`${ctx.prefix}:appinfo`, attrs, [], ctx);
|
|
82
|
+
}
|
|
83
|
+
function buildInclude(inc, ctx) {
|
|
84
|
+
const attrs = [];
|
|
85
|
+
addAttr(attrs, "id", inc.id);
|
|
86
|
+
addAttr(attrs, "schemaLocation", inc.schemaLocation);
|
|
87
|
+
const children = [];
|
|
88
|
+
if (inc.annotation) children.push(buildAnnotation(inc.annotation, {
|
|
89
|
+
...ctx,
|
|
90
|
+
level: ctx.level + 1
|
|
91
|
+
}));
|
|
92
|
+
return buildElement$1(`${ctx.prefix}:include`, attrs, children, ctx);
|
|
93
|
+
}
|
|
94
|
+
function buildImport(imp, ctx) {
|
|
95
|
+
const attrs = [];
|
|
96
|
+
addAttr(attrs, "id", imp.id);
|
|
97
|
+
addAttr(attrs, "namespace", imp.namespace);
|
|
98
|
+
addAttr(attrs, "schemaLocation", imp.schemaLocation);
|
|
99
|
+
const children = [];
|
|
100
|
+
if (imp.annotation) children.push(buildAnnotation(imp.annotation, {
|
|
101
|
+
...ctx,
|
|
102
|
+
level: ctx.level + 1
|
|
103
|
+
}));
|
|
104
|
+
return buildElement$1(`${ctx.prefix}:import`, attrs, children, ctx);
|
|
105
|
+
}
|
|
106
|
+
function buildRedefine(red, ctx) {
|
|
107
|
+
const attrs = [];
|
|
108
|
+
addAttr(attrs, "id", red.id);
|
|
109
|
+
addAttr(attrs, "schemaLocation", red.schemaLocation);
|
|
110
|
+
const children = [];
|
|
111
|
+
const childCtx = {
|
|
112
|
+
...ctx,
|
|
113
|
+
level: ctx.level + 1
|
|
114
|
+
};
|
|
115
|
+
if (red.annotation) for (const ann of red.annotation) children.push(buildAnnotation(ann, childCtx));
|
|
116
|
+
if (red.simpleType) for (const st of red.simpleType) children.push(buildTopLevelSimpleType(st, childCtx));
|
|
117
|
+
if (red.complexType) for (const ct of red.complexType) children.push(buildTopLevelComplexType(ct, childCtx));
|
|
118
|
+
if (red.group) for (const grp of red.group) children.push(buildNamedGroup(grp, childCtx));
|
|
119
|
+
if (red.attributeGroup) for (const ag of red.attributeGroup) children.push(buildNamedAttributeGroup(ag, childCtx));
|
|
120
|
+
return buildElement$1(`${ctx.prefix}:redefine`, attrs, children, ctx);
|
|
121
|
+
}
|
|
122
|
+
function buildOverride(ovr, ctx) {
|
|
123
|
+
const attrs = [];
|
|
124
|
+
addAttr(attrs, "id", ovr.id);
|
|
125
|
+
addAttr(attrs, "schemaLocation", ovr.schemaLocation);
|
|
126
|
+
const children = [];
|
|
127
|
+
const childCtx = {
|
|
128
|
+
...ctx,
|
|
129
|
+
level: ctx.level + 1
|
|
130
|
+
};
|
|
131
|
+
if (ovr.annotation) for (const ann of ovr.annotation) children.push(buildAnnotation(ann, childCtx));
|
|
132
|
+
if (ovr.simpleType) for (const st of ovr.simpleType) children.push(buildTopLevelSimpleType(st, childCtx));
|
|
133
|
+
if (ovr.complexType) for (const ct of ovr.complexType) children.push(buildTopLevelComplexType(ct, childCtx));
|
|
134
|
+
if (ovr.group) for (const grp of ovr.group) children.push(buildNamedGroup(grp, childCtx));
|
|
135
|
+
if (ovr.attributeGroup) for (const ag of ovr.attributeGroup) children.push(buildNamedAttributeGroup(ag, childCtx));
|
|
136
|
+
if (ovr.element) for (const el of ovr.element) children.push(buildTopLevelElement(el, childCtx));
|
|
137
|
+
if (ovr.attribute) for (const attr of ovr.attribute) children.push(buildTopLevelAttribute(attr, childCtx));
|
|
138
|
+
if (ovr.notation) for (const not of ovr.notation) children.push(buildNotation(not, childCtx));
|
|
139
|
+
return buildElement$1(`${ctx.prefix}:override`, attrs, children, ctx);
|
|
140
|
+
}
|
|
141
|
+
function buildTopLevelElement(el, ctx) {
|
|
142
|
+
const attrs = [];
|
|
143
|
+
addAttr(attrs, "id", el.id);
|
|
144
|
+
addAttr(attrs, "name", el.name);
|
|
145
|
+
addAttr(attrs, "type", el.type);
|
|
146
|
+
addAttr(attrs, "substitutionGroup", el.substitutionGroup);
|
|
147
|
+
addAttr(attrs, "default", el.default);
|
|
148
|
+
addAttr(attrs, "fixed", el.fixed);
|
|
149
|
+
addBoolAttr(attrs, "nillable", el.nillable);
|
|
150
|
+
addBoolAttr(attrs, "abstract", el.abstract);
|
|
151
|
+
addAttr(attrs, "final", el.final);
|
|
152
|
+
addAttr(attrs, "block", el.block);
|
|
153
|
+
const children = [];
|
|
154
|
+
const childCtx = {
|
|
155
|
+
...ctx,
|
|
156
|
+
level: ctx.level + 1
|
|
157
|
+
};
|
|
158
|
+
if (el.annotation) children.push(buildAnnotation(el.annotation, childCtx));
|
|
159
|
+
if (el.simpleType) children.push(buildLocalSimpleType(el.simpleType, childCtx));
|
|
160
|
+
if (el.complexType) children.push(buildLocalComplexType(el.complexType, childCtx));
|
|
161
|
+
if (el.alternative) for (const alt of el.alternative) children.push(buildAlternative(alt, childCtx));
|
|
162
|
+
if (el.unique) for (const u of el.unique) children.push(buildUnique(u, childCtx));
|
|
163
|
+
if (el.key) for (const k of el.key) children.push(buildKey(k, childCtx));
|
|
164
|
+
if (el.keyref) for (const kr of el.keyref) children.push(buildKeyref(kr, childCtx));
|
|
165
|
+
return buildElement$1(`${ctx.prefix}:element`, attrs, children, ctx);
|
|
166
|
+
}
|
|
167
|
+
function buildLocalElement(el, ctx) {
|
|
168
|
+
const attrs = [];
|
|
169
|
+
addAttr(attrs, "id", el.id);
|
|
170
|
+
addAttr(attrs, "name", el.name);
|
|
171
|
+
addAttr(attrs, "ref", el.ref);
|
|
172
|
+
addAttr(attrs, "type", el.type);
|
|
173
|
+
addOccursAttr(attrs, "minOccurs", el.minOccurs);
|
|
174
|
+
addOccursAttr(attrs, "maxOccurs", el.maxOccurs);
|
|
175
|
+
addAttr(attrs, "default", el.default);
|
|
176
|
+
addAttr(attrs, "fixed", el.fixed);
|
|
177
|
+
addBoolAttr(attrs, "nillable", el.nillable);
|
|
178
|
+
addAttr(attrs, "block", el.block);
|
|
179
|
+
addAttr(attrs, "form", el.form);
|
|
180
|
+
addAttr(attrs, "targetNamespace", el.targetNamespace);
|
|
181
|
+
const children = [];
|
|
182
|
+
const childCtx = {
|
|
183
|
+
...ctx,
|
|
184
|
+
level: ctx.level + 1
|
|
185
|
+
};
|
|
186
|
+
if (el.annotation) children.push(buildAnnotation(el.annotation, childCtx));
|
|
187
|
+
if (el.simpleType) children.push(buildLocalSimpleType(el.simpleType, childCtx));
|
|
188
|
+
if (el.complexType) children.push(buildLocalComplexType(el.complexType, childCtx));
|
|
189
|
+
if (el.alternative) for (const alt of el.alternative) children.push(buildAlternative(alt, childCtx));
|
|
190
|
+
if (el.unique) for (const u of el.unique) children.push(buildUnique(u, childCtx));
|
|
191
|
+
if (el.key) for (const k of el.key) children.push(buildKey(k, childCtx));
|
|
192
|
+
if (el.keyref) for (const kr of el.keyref) children.push(buildKeyref(kr, childCtx));
|
|
193
|
+
return buildElement$1(`${ctx.prefix}:element`, attrs, children, ctx);
|
|
194
|
+
}
|
|
195
|
+
function buildTopLevelAttribute(attr, ctx) {
|
|
196
|
+
const attrs = [];
|
|
197
|
+
addAttr(attrs, "id", attr.id);
|
|
198
|
+
addAttr(attrs, "name", attr.name);
|
|
199
|
+
addAttr(attrs, "type", attr.type);
|
|
200
|
+
addAttr(attrs, "default", attr.default);
|
|
201
|
+
addAttr(attrs, "fixed", attr.fixed);
|
|
202
|
+
addBoolAttr(attrs, "inheritable", attr.inheritable);
|
|
203
|
+
const children = [];
|
|
204
|
+
const childCtx = {
|
|
205
|
+
...ctx,
|
|
206
|
+
level: ctx.level + 1
|
|
207
|
+
};
|
|
208
|
+
if (attr.annotation) children.push(buildAnnotation(attr.annotation, childCtx));
|
|
209
|
+
if (attr.simpleType) children.push(buildLocalSimpleType(attr.simpleType, childCtx));
|
|
210
|
+
return buildElement$1(`${ctx.prefix}:attribute`, attrs, children, ctx);
|
|
211
|
+
}
|
|
212
|
+
function buildLocalAttribute(attr, ctx) {
|
|
213
|
+
const attrs = [];
|
|
214
|
+
addAttr(attrs, "id", attr.id);
|
|
215
|
+
addAttr(attrs, "name", attr.name);
|
|
216
|
+
addAttr(attrs, "ref", attr.ref);
|
|
217
|
+
addAttr(attrs, "type", attr.type);
|
|
218
|
+
addAttr(attrs, "use", attr.use);
|
|
219
|
+
addAttr(attrs, "default", attr.default);
|
|
220
|
+
addAttr(attrs, "fixed", attr.fixed);
|
|
221
|
+
addAttr(attrs, "form", attr.form);
|
|
222
|
+
addAttr(attrs, "targetNamespace", attr.targetNamespace);
|
|
223
|
+
addBoolAttr(attrs, "inheritable", attr.inheritable);
|
|
224
|
+
const children = [];
|
|
225
|
+
const childCtx = {
|
|
226
|
+
...ctx,
|
|
227
|
+
level: ctx.level + 1
|
|
228
|
+
};
|
|
229
|
+
if (attr.annotation) children.push(buildAnnotation(attr.annotation, childCtx));
|
|
230
|
+
if (attr.simpleType) children.push(buildLocalSimpleType(attr.simpleType, childCtx));
|
|
231
|
+
return buildElement$1(`${ctx.prefix}:attribute`, attrs, children, ctx);
|
|
232
|
+
}
|
|
233
|
+
function buildTopLevelComplexType(ct, ctx) {
|
|
234
|
+
const attrs = [];
|
|
235
|
+
addAttr(attrs, "id", ct.id);
|
|
236
|
+
addAttr(attrs, "name", ct.name);
|
|
237
|
+
addBoolAttr(attrs, "mixed", ct.mixed);
|
|
238
|
+
addBoolAttr(attrs, "abstract", ct.abstract);
|
|
239
|
+
addAttr(attrs, "final", ct.final);
|
|
240
|
+
addAttr(attrs, "block", ct.block);
|
|
241
|
+
addBoolAttr(attrs, "defaultAttributesApply", ct.defaultAttributesApply);
|
|
242
|
+
return buildComplexTypeContent(ct, attrs, ctx);
|
|
243
|
+
}
|
|
244
|
+
function buildLocalComplexType(ct, ctx) {
|
|
245
|
+
const attrs = [];
|
|
246
|
+
addAttr(attrs, "id", ct.id);
|
|
247
|
+
addBoolAttr(attrs, "mixed", ct.mixed);
|
|
248
|
+
return buildComplexTypeContent(ct, attrs, ctx);
|
|
249
|
+
}
|
|
250
|
+
function buildComplexTypeContent(ct, attrs, ctx) {
|
|
251
|
+
const children = [];
|
|
252
|
+
const childCtx = {
|
|
253
|
+
...ctx,
|
|
254
|
+
level: ctx.level + 1
|
|
255
|
+
};
|
|
256
|
+
if (ct.annotation) children.push(buildAnnotation(ct.annotation, childCtx));
|
|
257
|
+
if (ct.simpleContent) children.push(buildSimpleContent(ct.simpleContent, childCtx));
|
|
258
|
+
else if (ct.complexContent) children.push(buildComplexContent(ct.complexContent, childCtx));
|
|
259
|
+
else {
|
|
260
|
+
if (ct.openContent) children.push(buildOpenContent(ct.openContent, childCtx));
|
|
261
|
+
if (ct.group) children.push(buildGroupRef(ct.group, childCtx));
|
|
262
|
+
if (ct.all) children.push(buildAll(ct.all, childCtx));
|
|
263
|
+
if (ct.choice) children.push(buildExplicitGroup(ct.choice, "choice", childCtx));
|
|
264
|
+
if (ct.sequence) children.push(buildExplicitGroup(ct.sequence, "sequence", childCtx));
|
|
265
|
+
if (ct.attribute) for (const attr of ct.attribute) children.push(buildLocalAttribute(attr, childCtx));
|
|
266
|
+
if (ct.attributeGroup) for (const ag of ct.attributeGroup) children.push(buildAttributeGroupRef(ag, childCtx));
|
|
267
|
+
if (ct.anyAttribute) children.push(buildAnyAttribute(ct.anyAttribute, childCtx));
|
|
268
|
+
if (ct.assert) for (const a of ct.assert) children.push(buildAssertion(a, childCtx));
|
|
269
|
+
}
|
|
270
|
+
return buildElement$1(`${ctx.prefix}:complexType`, attrs, children, ctx);
|
|
271
|
+
}
|
|
272
|
+
function buildTopLevelSimpleType(st, ctx) {
|
|
273
|
+
const attrs = [];
|
|
274
|
+
addAttr(attrs, "id", st.id);
|
|
275
|
+
addAttr(attrs, "name", st.name);
|
|
276
|
+
addAttr(attrs, "final", st.final);
|
|
277
|
+
return buildSimpleTypeContent(st, attrs, ctx);
|
|
278
|
+
}
|
|
279
|
+
function buildLocalSimpleType(st, ctx) {
|
|
280
|
+
const attrs = [];
|
|
281
|
+
addAttr(attrs, "id", st.id);
|
|
282
|
+
return buildSimpleTypeContent(st, attrs, ctx);
|
|
283
|
+
}
|
|
284
|
+
function buildSimpleTypeContent(st, attrs, ctx) {
|
|
285
|
+
const children = [];
|
|
286
|
+
const childCtx = {
|
|
287
|
+
...ctx,
|
|
288
|
+
level: ctx.level + 1
|
|
289
|
+
};
|
|
290
|
+
if (st.annotation) children.push(buildAnnotation(st.annotation, childCtx));
|
|
291
|
+
if (st.restriction) children.push(buildSimpleTypeRestriction(st.restriction, childCtx));
|
|
292
|
+
else if (st.list) children.push(buildList(st.list, childCtx));
|
|
293
|
+
else if (st.union) children.push(buildUnion(st.union, childCtx));
|
|
294
|
+
return buildElement$1(`${ctx.prefix}:simpleType`, attrs, children, ctx);
|
|
295
|
+
}
|
|
296
|
+
function buildSimpleTypeRestriction(r, ctx) {
|
|
297
|
+
const attrs = [];
|
|
298
|
+
addAttr(attrs, "id", r.id);
|
|
299
|
+
addAttr(attrs, "base", r.base);
|
|
300
|
+
const children = [];
|
|
301
|
+
const childCtx = {
|
|
302
|
+
...ctx,
|
|
303
|
+
level: ctx.level + 1
|
|
304
|
+
};
|
|
305
|
+
if (r.annotation) children.push(buildAnnotation(r.annotation, childCtx));
|
|
306
|
+
if (r.simpleType) children.push(buildLocalSimpleType(r.simpleType, childCtx));
|
|
307
|
+
buildFacets(r, children, childCtx);
|
|
308
|
+
return buildElement$1(`${ctx.prefix}:restriction`, attrs, children, ctx);
|
|
309
|
+
}
|
|
310
|
+
function buildFacets(r, children, ctx) {
|
|
311
|
+
if (r.minExclusive) for (const f of r.minExclusive) children.push(buildFacet(f, "minExclusive", ctx));
|
|
312
|
+
if (r.minInclusive) for (const f of r.minInclusive) children.push(buildFacet(f, "minInclusive", ctx));
|
|
313
|
+
if (r.maxExclusive) for (const f of r.maxExclusive) children.push(buildFacet(f, "maxExclusive", ctx));
|
|
314
|
+
if (r.maxInclusive) for (const f of r.maxInclusive) children.push(buildFacet(f, "maxInclusive", ctx));
|
|
315
|
+
if (r.totalDigits) for (const f of r.totalDigits) children.push(buildFacet(f, "totalDigits", ctx));
|
|
316
|
+
if (r.fractionDigits) for (const f of r.fractionDigits) children.push(buildFacet(f, "fractionDigits", ctx));
|
|
317
|
+
if (r.length) for (const f of r.length) children.push(buildFacet(f, "length", ctx));
|
|
318
|
+
if (r.minLength) for (const f of r.minLength) children.push(buildFacet(f, "minLength", ctx));
|
|
319
|
+
if (r.maxLength) for (const f of r.maxLength) children.push(buildFacet(f, "maxLength", ctx));
|
|
320
|
+
if (r.enumeration) for (const f of r.enumeration) children.push(buildFacet(f, "enumeration", ctx));
|
|
321
|
+
if (r.whiteSpace) for (const f of r.whiteSpace) children.push(buildFacet(f, "whiteSpace", ctx));
|
|
322
|
+
if (r.pattern) for (const p of r.pattern) children.push(buildPattern(p, ctx));
|
|
323
|
+
if (r.assertion) for (const a of r.assertion) children.push(buildAssertion(a, ctx));
|
|
324
|
+
if (r.explicitTimezone) for (const f of r.explicitTimezone) children.push(buildFacet(f, "explicitTimezone", ctx));
|
|
325
|
+
}
|
|
326
|
+
function buildFacet(f, name, ctx) {
|
|
327
|
+
const attrs = [];
|
|
328
|
+
addAttr(attrs, "id", f.id);
|
|
329
|
+
addAttr(attrs, "value", f.value);
|
|
330
|
+
addBoolAttr(attrs, "fixed", f.fixed);
|
|
331
|
+
const children = [];
|
|
332
|
+
if (f.annotation) children.push(buildAnnotation(f.annotation, {
|
|
333
|
+
...ctx,
|
|
334
|
+
level: ctx.level + 1
|
|
335
|
+
}));
|
|
336
|
+
return buildElement$1(`${ctx.prefix}:${name}`, attrs, children, ctx);
|
|
337
|
+
}
|
|
338
|
+
function buildPattern(p, ctx) {
|
|
339
|
+
const attrs = [];
|
|
340
|
+
addAttr(attrs, "id", p.id);
|
|
341
|
+
addAttr(attrs, "value", p.value);
|
|
342
|
+
const children = [];
|
|
343
|
+
if (p.annotation) children.push(buildAnnotation(p.annotation, {
|
|
344
|
+
...ctx,
|
|
345
|
+
level: ctx.level + 1
|
|
346
|
+
}));
|
|
347
|
+
return buildElement$1(`${ctx.prefix}:pattern`, attrs, children, ctx);
|
|
348
|
+
}
|
|
349
|
+
function buildList(l, ctx) {
|
|
350
|
+
const attrs = [];
|
|
351
|
+
addAttr(attrs, "id", l.id);
|
|
352
|
+
addAttr(attrs, "itemType", l.itemType);
|
|
353
|
+
const children = [];
|
|
354
|
+
const childCtx = {
|
|
355
|
+
...ctx,
|
|
356
|
+
level: ctx.level + 1
|
|
357
|
+
};
|
|
358
|
+
if (l.annotation) children.push(buildAnnotation(l.annotation, childCtx));
|
|
359
|
+
if (l.simpleType) children.push(buildLocalSimpleType(l.simpleType, childCtx));
|
|
360
|
+
return buildElement$1(`${ctx.prefix}:list`, attrs, children, ctx);
|
|
361
|
+
}
|
|
362
|
+
function buildUnion(u, ctx) {
|
|
363
|
+
const attrs = [];
|
|
364
|
+
addAttr(attrs, "id", u.id);
|
|
365
|
+
addAttr(attrs, "memberTypes", u.memberTypes);
|
|
366
|
+
const children = [];
|
|
367
|
+
const childCtx = {
|
|
368
|
+
...ctx,
|
|
369
|
+
level: ctx.level + 1
|
|
370
|
+
};
|
|
371
|
+
if (u.annotation) children.push(buildAnnotation(u.annotation, childCtx));
|
|
372
|
+
if (u.simpleType) for (const st of u.simpleType) children.push(buildLocalSimpleType(st, childCtx));
|
|
373
|
+
return buildElement$1(`${ctx.prefix}:union`, attrs, children, ctx);
|
|
374
|
+
}
|
|
375
|
+
function buildComplexContent(cc, ctx) {
|
|
376
|
+
const attrs = [];
|
|
377
|
+
addAttr(attrs, "id", cc.id);
|
|
378
|
+
addBoolAttr(attrs, "mixed", cc.mixed);
|
|
379
|
+
const children = [];
|
|
380
|
+
const childCtx = {
|
|
381
|
+
...ctx,
|
|
382
|
+
level: ctx.level + 1
|
|
383
|
+
};
|
|
384
|
+
if (cc.annotation) children.push(buildAnnotation(cc.annotation, childCtx));
|
|
385
|
+
if (cc.restriction) children.push(buildComplexContentRestriction(cc.restriction, childCtx));
|
|
386
|
+
else if (cc.extension) children.push(buildComplexContentExtension(cc.extension, childCtx));
|
|
387
|
+
return buildElement$1(`${ctx.prefix}:complexContent`, attrs, children, ctx);
|
|
388
|
+
}
|
|
389
|
+
function buildSimpleContent(sc, ctx) {
|
|
390
|
+
const attrs = [];
|
|
391
|
+
addAttr(attrs, "id", sc.id);
|
|
392
|
+
const children = [];
|
|
393
|
+
const childCtx = {
|
|
394
|
+
...ctx,
|
|
395
|
+
level: ctx.level + 1
|
|
396
|
+
};
|
|
397
|
+
if (sc.annotation) children.push(buildAnnotation(sc.annotation, childCtx));
|
|
398
|
+
if (sc.restriction) children.push(buildSimpleContentRestriction(sc.restriction, childCtx));
|
|
399
|
+
else if (sc.extension) children.push(buildSimpleContentExtension(sc.extension, childCtx));
|
|
400
|
+
return buildElement$1(`${ctx.prefix}:simpleContent`, attrs, children, ctx);
|
|
401
|
+
}
|
|
402
|
+
function buildComplexContentRestriction(r, ctx) {
|
|
403
|
+
const attrs = [];
|
|
404
|
+
addAttr(attrs, "id", r.id);
|
|
405
|
+
addAttr(attrs, "base", r.base);
|
|
406
|
+
const children = [];
|
|
407
|
+
const childCtx = {
|
|
408
|
+
...ctx,
|
|
409
|
+
level: ctx.level + 1
|
|
410
|
+
};
|
|
411
|
+
if (r.annotation) children.push(buildAnnotation(r.annotation, childCtx));
|
|
412
|
+
if (r.openContent) children.push(buildOpenContent(r.openContent, childCtx));
|
|
413
|
+
if (r.group) children.push(buildGroupRef(r.group, childCtx));
|
|
414
|
+
if (r.all) children.push(buildAll(r.all, childCtx));
|
|
415
|
+
if (r.choice) children.push(buildExplicitGroup(r.choice, "choice", childCtx));
|
|
416
|
+
if (r.sequence) children.push(buildExplicitGroup(r.sequence, "sequence", childCtx));
|
|
417
|
+
if (r.attribute) for (const attr of r.attribute) children.push(buildLocalAttribute(attr, childCtx));
|
|
418
|
+
if (r.attributeGroup) for (const ag of r.attributeGroup) children.push(buildAttributeGroupRef(ag, childCtx));
|
|
419
|
+
if (r.anyAttribute) children.push(buildAnyAttribute(r.anyAttribute, childCtx));
|
|
420
|
+
if (r.assert) for (const a of r.assert) children.push(buildAssertion(a, childCtx));
|
|
421
|
+
return buildElement$1(`${ctx.prefix}:restriction`, attrs, children, ctx);
|
|
422
|
+
}
|
|
423
|
+
function buildComplexContentExtension(e, ctx) {
|
|
424
|
+
const attrs = [];
|
|
425
|
+
addAttr(attrs, "id", e.id);
|
|
426
|
+
addAttr(attrs, "base", e.base);
|
|
427
|
+
const children = [];
|
|
428
|
+
const childCtx = {
|
|
429
|
+
...ctx,
|
|
430
|
+
level: ctx.level + 1
|
|
431
|
+
};
|
|
432
|
+
if (e.annotation) children.push(buildAnnotation(e.annotation, childCtx));
|
|
433
|
+
if (e.openContent) children.push(buildOpenContent(e.openContent, childCtx));
|
|
434
|
+
if (e.group) children.push(buildGroupRef(e.group, childCtx));
|
|
435
|
+
if (e.all) children.push(buildAll(e.all, childCtx));
|
|
436
|
+
if (e.choice) children.push(buildExplicitGroup(e.choice, "choice", childCtx));
|
|
437
|
+
if (e.sequence) children.push(buildExplicitGroup(e.sequence, "sequence", childCtx));
|
|
438
|
+
if (e.attribute) for (const attr of e.attribute) children.push(buildLocalAttribute(attr, childCtx));
|
|
439
|
+
if (e.attributeGroup) for (const ag of e.attributeGroup) children.push(buildAttributeGroupRef(ag, childCtx));
|
|
440
|
+
if (e.anyAttribute) children.push(buildAnyAttribute(e.anyAttribute, childCtx));
|
|
441
|
+
if (e.assert) for (const a of e.assert) children.push(buildAssertion(a, childCtx));
|
|
442
|
+
return buildElement$1(`${ctx.prefix}:extension`, attrs, children, ctx);
|
|
443
|
+
}
|
|
444
|
+
function buildSimpleContentRestriction(r, ctx) {
|
|
445
|
+
const attrs = [];
|
|
446
|
+
addAttr(attrs, "id", r.id);
|
|
447
|
+
addAttr(attrs, "base", r.base);
|
|
448
|
+
const children = [];
|
|
449
|
+
const childCtx = {
|
|
450
|
+
...ctx,
|
|
451
|
+
level: ctx.level + 1
|
|
452
|
+
};
|
|
453
|
+
if (r.annotation) children.push(buildAnnotation(r.annotation, childCtx));
|
|
454
|
+
if (r.simpleType) children.push(buildLocalSimpleType(r.simpleType, childCtx));
|
|
455
|
+
buildFacets(r, children, childCtx);
|
|
456
|
+
if (r.attribute) for (const attr of r.attribute) children.push(buildLocalAttribute(attr, childCtx));
|
|
457
|
+
if (r.attributeGroup) for (const ag of r.attributeGroup) children.push(buildAttributeGroupRef(ag, childCtx));
|
|
458
|
+
if (r.anyAttribute) children.push(buildAnyAttribute(r.anyAttribute, childCtx));
|
|
459
|
+
if (r.assert) for (const a of r.assert) children.push(buildAssertion(a, childCtx));
|
|
460
|
+
return buildElement$1(`${ctx.prefix}:restriction`, attrs, children, ctx);
|
|
461
|
+
}
|
|
462
|
+
function buildSimpleContentExtension(e, ctx) {
|
|
463
|
+
const attrs = [];
|
|
464
|
+
addAttr(attrs, "id", e.id);
|
|
465
|
+
addAttr(attrs, "base", e.base);
|
|
466
|
+
const children = [];
|
|
467
|
+
const childCtx = {
|
|
468
|
+
...ctx,
|
|
469
|
+
level: ctx.level + 1
|
|
470
|
+
};
|
|
471
|
+
if (e.annotation) children.push(buildAnnotation(e.annotation, childCtx));
|
|
472
|
+
if (e.attribute) for (const attr of e.attribute) children.push(buildLocalAttribute(attr, childCtx));
|
|
473
|
+
if (e.attributeGroup) for (const ag of e.attributeGroup) children.push(buildAttributeGroupRef(ag, childCtx));
|
|
474
|
+
if (e.anyAttribute) children.push(buildAnyAttribute(e.anyAttribute, childCtx));
|
|
475
|
+
if (e.assert) for (const a of e.assert) children.push(buildAssertion(a, childCtx));
|
|
476
|
+
return buildElement$1(`${ctx.prefix}:extension`, attrs, children, ctx);
|
|
477
|
+
}
|
|
478
|
+
function buildExplicitGroup(g, name, ctx) {
|
|
479
|
+
const attrs = [];
|
|
480
|
+
addAttr(attrs, "id", g.id);
|
|
481
|
+
addOccursAttr(attrs, "minOccurs", g.minOccurs);
|
|
482
|
+
addOccursAttr(attrs, "maxOccurs", g.maxOccurs);
|
|
483
|
+
const children = [];
|
|
484
|
+
const childCtx = {
|
|
485
|
+
...ctx,
|
|
486
|
+
level: ctx.level + 1
|
|
487
|
+
};
|
|
488
|
+
if (g.annotation) children.push(buildAnnotation(g.annotation, childCtx));
|
|
489
|
+
if (g.element) for (const el of g.element) children.push(buildLocalElement(el, childCtx));
|
|
490
|
+
if (g.group) for (const grp of g.group) children.push(buildGroupRef(grp, childCtx));
|
|
491
|
+
if (g.choice) for (const c of g.choice) children.push(buildExplicitGroup(c, "choice", childCtx));
|
|
492
|
+
if (g.sequence) for (const s of g.sequence) children.push(buildExplicitGroup(s, "sequence", childCtx));
|
|
493
|
+
if (g.any) for (const a of g.any) children.push(buildAny(a, childCtx));
|
|
494
|
+
return buildElement$1(`${ctx.prefix}:${name}`, attrs, children, ctx);
|
|
495
|
+
}
|
|
496
|
+
function buildAll(a, ctx) {
|
|
497
|
+
const attrs = [];
|
|
498
|
+
addAttr(attrs, "id", a.id);
|
|
499
|
+
addOccursAttr(attrs, "minOccurs", a.minOccurs);
|
|
500
|
+
addOccursAttr(attrs, "maxOccurs", a.maxOccurs);
|
|
501
|
+
const children = [];
|
|
502
|
+
const childCtx = {
|
|
503
|
+
...ctx,
|
|
504
|
+
level: ctx.level + 1
|
|
505
|
+
};
|
|
506
|
+
if (a.annotation) children.push(buildAnnotation(a.annotation, childCtx));
|
|
507
|
+
if (a.element) for (const el of a.element) children.push(buildLocalElement(el, childCtx));
|
|
508
|
+
if (a.any) for (const any of a.any) children.push(buildAny(any, childCtx));
|
|
509
|
+
if (a.group) for (const grp of a.group) children.push(buildGroupRef(grp, childCtx));
|
|
510
|
+
return buildElement$1(`${ctx.prefix}:all`, attrs, children, ctx);
|
|
511
|
+
}
|
|
512
|
+
function buildNamedGroup(g, ctx) {
|
|
513
|
+
const attrs = [];
|
|
514
|
+
addAttr(attrs, "id", g.id);
|
|
515
|
+
addAttr(attrs, "name", g.name);
|
|
516
|
+
const children = [];
|
|
517
|
+
const childCtx = {
|
|
518
|
+
...ctx,
|
|
519
|
+
level: ctx.level + 1
|
|
520
|
+
};
|
|
521
|
+
if (g.annotation) children.push(buildAnnotation(g.annotation, childCtx));
|
|
522
|
+
if (g.all) children.push(buildAll(g.all, childCtx));
|
|
523
|
+
if (g.choice) children.push(buildExplicitGroup(g.choice, "choice", childCtx));
|
|
524
|
+
if (g.sequence) children.push(buildExplicitGroup(g.sequence, "sequence", childCtx));
|
|
525
|
+
return buildElement$1(`${ctx.prefix}:group`, attrs, children, ctx);
|
|
526
|
+
}
|
|
527
|
+
function buildGroupRef(g, ctx) {
|
|
528
|
+
const attrs = [];
|
|
529
|
+
addAttr(attrs, "id", g.id);
|
|
530
|
+
addAttr(attrs, "ref", g.ref);
|
|
531
|
+
addOccursAttr(attrs, "minOccurs", g.minOccurs);
|
|
532
|
+
addOccursAttr(attrs, "maxOccurs", g.maxOccurs);
|
|
533
|
+
const children = [];
|
|
534
|
+
if (g.annotation) children.push(buildAnnotation(g.annotation, {
|
|
535
|
+
...ctx,
|
|
536
|
+
level: ctx.level + 1
|
|
537
|
+
}));
|
|
538
|
+
return buildElement$1(`${ctx.prefix}:group`, attrs, children, ctx);
|
|
539
|
+
}
|
|
540
|
+
function buildNamedAttributeGroup(ag, ctx) {
|
|
541
|
+
const attrs = [];
|
|
542
|
+
addAttr(attrs, "id", ag.id);
|
|
543
|
+
addAttr(attrs, "name", ag.name);
|
|
544
|
+
const children = [];
|
|
545
|
+
const childCtx = {
|
|
546
|
+
...ctx,
|
|
547
|
+
level: ctx.level + 1
|
|
548
|
+
};
|
|
549
|
+
if (ag.annotation) children.push(buildAnnotation(ag.annotation, childCtx));
|
|
550
|
+
if (ag.attribute) for (const attr of ag.attribute) children.push(buildLocalAttribute(attr, childCtx));
|
|
551
|
+
if (ag.attributeGroup) for (const agr of ag.attributeGroup) children.push(buildAttributeGroupRef(agr, childCtx));
|
|
552
|
+
if (ag.anyAttribute) children.push(buildAnyAttribute(ag.anyAttribute, childCtx));
|
|
553
|
+
return buildElement$1(`${ctx.prefix}:attributeGroup`, attrs, children, ctx);
|
|
554
|
+
}
|
|
555
|
+
function buildAttributeGroupRef(ag, ctx) {
|
|
556
|
+
const attrs = [];
|
|
557
|
+
addAttr(attrs, "id", ag.id);
|
|
558
|
+
addAttr(attrs, "ref", ag.ref);
|
|
559
|
+
const children = [];
|
|
560
|
+
if (ag.annotation) children.push(buildAnnotation(ag.annotation, {
|
|
561
|
+
...ctx,
|
|
562
|
+
level: ctx.level + 1
|
|
563
|
+
}));
|
|
564
|
+
return buildElement$1(`${ctx.prefix}:attributeGroup`, attrs, children, ctx);
|
|
565
|
+
}
|
|
566
|
+
function buildAny(a, ctx) {
|
|
567
|
+
const attrs = [];
|
|
568
|
+
addAttr(attrs, "id", a.id);
|
|
569
|
+
addOccursAttr(attrs, "minOccurs", a.minOccurs);
|
|
570
|
+
addOccursAttr(attrs, "maxOccurs", a.maxOccurs);
|
|
571
|
+
addAttr(attrs, "namespace", a.namespace);
|
|
572
|
+
addAttr(attrs, "processContents", a.processContents);
|
|
573
|
+
addAttr(attrs, "notNamespace", a.notNamespace);
|
|
574
|
+
addAttr(attrs, "notQName", a.notQName);
|
|
575
|
+
const children = [];
|
|
576
|
+
if (a.annotation) children.push(buildAnnotation(a.annotation, {
|
|
577
|
+
...ctx,
|
|
578
|
+
level: ctx.level + 1
|
|
579
|
+
}));
|
|
580
|
+
return buildElement$1(`${ctx.prefix}:any`, attrs, children, ctx);
|
|
581
|
+
}
|
|
582
|
+
function buildAnyAttribute(aa, ctx) {
|
|
583
|
+
const attrs = [];
|
|
584
|
+
addAttr(attrs, "id", aa.id);
|
|
585
|
+
addAttr(attrs, "namespace", aa.namespace);
|
|
586
|
+
addAttr(attrs, "processContents", aa.processContents);
|
|
587
|
+
addAttr(attrs, "notNamespace", aa.notNamespace);
|
|
588
|
+
addAttr(attrs, "notQName", aa.notQName);
|
|
589
|
+
const children = [];
|
|
590
|
+
if (aa.annotation) children.push(buildAnnotation(aa.annotation, {
|
|
591
|
+
...ctx,
|
|
592
|
+
level: ctx.level + 1
|
|
593
|
+
}));
|
|
594
|
+
return buildElement$1(`${ctx.prefix}:anyAttribute`, attrs, children, ctx);
|
|
595
|
+
}
|
|
596
|
+
function buildUnique(u, ctx) {
|
|
597
|
+
const attrs = [];
|
|
598
|
+
addAttr(attrs, "id", u.id);
|
|
599
|
+
addAttr(attrs, "name", u.name);
|
|
600
|
+
addAttr(attrs, "ref", u.ref);
|
|
601
|
+
const children = [];
|
|
602
|
+
const childCtx = {
|
|
603
|
+
...ctx,
|
|
604
|
+
level: ctx.level + 1
|
|
605
|
+
};
|
|
606
|
+
if (u.annotation) children.push(buildAnnotation(u.annotation, childCtx));
|
|
607
|
+
if (u.selector) children.push(buildSelector(u.selector, childCtx));
|
|
608
|
+
if (u.field) for (const f of u.field) children.push(buildField$1(f, childCtx));
|
|
609
|
+
return buildElement$1(`${ctx.prefix}:unique`, attrs, children, ctx);
|
|
610
|
+
}
|
|
611
|
+
function buildKey(k, ctx) {
|
|
612
|
+
const attrs = [];
|
|
613
|
+
addAttr(attrs, "id", k.id);
|
|
614
|
+
addAttr(attrs, "name", k.name);
|
|
615
|
+
addAttr(attrs, "ref", k.ref);
|
|
616
|
+
const children = [];
|
|
617
|
+
const childCtx = {
|
|
618
|
+
...ctx,
|
|
619
|
+
level: ctx.level + 1
|
|
620
|
+
};
|
|
621
|
+
if (k.annotation) children.push(buildAnnotation(k.annotation, childCtx));
|
|
622
|
+
if (k.selector) children.push(buildSelector(k.selector, childCtx));
|
|
623
|
+
if (k.field) for (const f of k.field) children.push(buildField$1(f, childCtx));
|
|
624
|
+
return buildElement$1(`${ctx.prefix}:key`, attrs, children, ctx);
|
|
625
|
+
}
|
|
626
|
+
function buildKeyref(kr, ctx) {
|
|
627
|
+
const attrs = [];
|
|
628
|
+
addAttr(attrs, "id", kr.id);
|
|
629
|
+
addAttr(attrs, "name", kr.name);
|
|
630
|
+
addAttr(attrs, "ref", kr.ref);
|
|
631
|
+
addAttr(attrs, "refer", kr.refer);
|
|
632
|
+
const children = [];
|
|
633
|
+
const childCtx = {
|
|
634
|
+
...ctx,
|
|
635
|
+
level: ctx.level + 1
|
|
636
|
+
};
|
|
637
|
+
if (kr.annotation) children.push(buildAnnotation(kr.annotation, childCtx));
|
|
638
|
+
if (kr.selector) children.push(buildSelector(kr.selector, childCtx));
|
|
639
|
+
if (kr.field) for (const f of kr.field) children.push(buildField$1(f, childCtx));
|
|
640
|
+
return buildElement$1(`${ctx.prefix}:keyref`, attrs, children, ctx);
|
|
641
|
+
}
|
|
642
|
+
function buildSelector(s, ctx) {
|
|
643
|
+
const attrs = [];
|
|
644
|
+
addAttr(attrs, "id", s.id);
|
|
645
|
+
addAttr(attrs, "xpath", s.xpath);
|
|
646
|
+
addAttr(attrs, "xpathDefaultNamespace", s.xpathDefaultNamespace);
|
|
647
|
+
const children = [];
|
|
648
|
+
if (s.annotation) children.push(buildAnnotation(s.annotation, {
|
|
649
|
+
...ctx,
|
|
650
|
+
level: ctx.level + 1
|
|
651
|
+
}));
|
|
652
|
+
return buildElement$1(`${ctx.prefix}:selector`, attrs, children, ctx);
|
|
653
|
+
}
|
|
654
|
+
function buildField$1(f, ctx) {
|
|
655
|
+
const attrs = [];
|
|
656
|
+
addAttr(attrs, "id", f.id);
|
|
657
|
+
addAttr(attrs, "xpath", f.xpath);
|
|
658
|
+
addAttr(attrs, "xpathDefaultNamespace", f.xpathDefaultNamespace);
|
|
659
|
+
const children = [];
|
|
660
|
+
if (f.annotation) children.push(buildAnnotation(f.annotation, {
|
|
661
|
+
...ctx,
|
|
662
|
+
level: ctx.level + 1
|
|
663
|
+
}));
|
|
664
|
+
return buildElement$1(`${ctx.prefix}:field`, attrs, children, ctx);
|
|
665
|
+
}
|
|
666
|
+
function buildOpenContent(oc, ctx) {
|
|
667
|
+
const attrs = [];
|
|
668
|
+
addAttr(attrs, "id", oc.id);
|
|
669
|
+
addAttr(attrs, "mode", oc.mode);
|
|
670
|
+
const children = [];
|
|
671
|
+
const childCtx = {
|
|
672
|
+
...ctx,
|
|
673
|
+
level: ctx.level + 1
|
|
674
|
+
};
|
|
675
|
+
if (oc.annotation) children.push(buildAnnotation(oc.annotation, childCtx));
|
|
676
|
+
if (oc.any) children.push(buildAny(oc.any, childCtx));
|
|
677
|
+
return buildElement$1(`${ctx.prefix}:openContent`, attrs, children, ctx);
|
|
678
|
+
}
|
|
679
|
+
function buildDefaultOpenContent(doc, ctx) {
|
|
680
|
+
const attrs = [];
|
|
681
|
+
addAttr(attrs, "id", doc.id);
|
|
682
|
+
addBoolAttr(attrs, "appliesToEmpty", doc.appliesToEmpty);
|
|
683
|
+
addAttr(attrs, "mode", doc.mode);
|
|
684
|
+
const children = [];
|
|
685
|
+
const childCtx = {
|
|
686
|
+
...ctx,
|
|
687
|
+
level: ctx.level + 1
|
|
688
|
+
};
|
|
689
|
+
if (doc.annotation) children.push(buildAnnotation(doc.annotation, childCtx));
|
|
690
|
+
children.push(buildAny(doc.any, childCtx));
|
|
691
|
+
return buildElement$1(`${ctx.prefix}:defaultOpenContent`, attrs, children, ctx);
|
|
692
|
+
}
|
|
693
|
+
function buildAssertion(a, ctx) {
|
|
694
|
+
const attrs = [];
|
|
695
|
+
addAttr(attrs, "id", a.id);
|
|
696
|
+
addAttr(attrs, "test", a.test);
|
|
697
|
+
addAttr(attrs, "xpathDefaultNamespace", a.xpathDefaultNamespace);
|
|
698
|
+
const children = [];
|
|
699
|
+
if (a.annotation) children.push(buildAnnotation(a.annotation, {
|
|
700
|
+
...ctx,
|
|
701
|
+
level: ctx.level + 1
|
|
702
|
+
}));
|
|
703
|
+
return buildElement$1(`${ctx.prefix}:assert`, attrs, children, ctx);
|
|
704
|
+
}
|
|
705
|
+
function buildAlternative(alt, ctx) {
|
|
706
|
+
const attrs = [];
|
|
707
|
+
addAttr(attrs, "id", alt.id);
|
|
708
|
+
addAttr(attrs, "test", alt.test);
|
|
709
|
+
addAttr(attrs, "type", alt.type);
|
|
710
|
+
addAttr(attrs, "xpathDefaultNamespace", alt.xpathDefaultNamespace);
|
|
711
|
+
const children = [];
|
|
712
|
+
const childCtx = {
|
|
713
|
+
...ctx,
|
|
714
|
+
level: ctx.level + 1
|
|
715
|
+
};
|
|
716
|
+
if (alt.annotation) children.push(buildAnnotation(alt.annotation, childCtx));
|
|
717
|
+
if (alt.simpleType) children.push(buildLocalSimpleType(alt.simpleType, childCtx));
|
|
718
|
+
if (alt.complexType) children.push(buildLocalComplexType(alt.complexType, childCtx));
|
|
719
|
+
return buildElement$1(`${ctx.prefix}:alternative`, attrs, children, ctx);
|
|
720
|
+
}
|
|
721
|
+
function buildNotation(n, ctx) {
|
|
722
|
+
const attrs = [];
|
|
723
|
+
addAttr(attrs, "id", n.id);
|
|
724
|
+
addAttr(attrs, "name", n.name);
|
|
725
|
+
addAttr(attrs, "public", n.public);
|
|
726
|
+
addAttr(attrs, "system", n.system);
|
|
727
|
+
const children = [];
|
|
728
|
+
if (n.annotation) children.push(buildAnnotation(n.annotation, {
|
|
729
|
+
...ctx,
|
|
730
|
+
level: ctx.level + 1
|
|
731
|
+
}));
|
|
732
|
+
return buildElement$1(`${ctx.prefix}:notation`, attrs, children, ctx);
|
|
733
|
+
}
|
|
734
|
+
function addAttr(attrs, name, value) {
|
|
735
|
+
if (value !== void 0) attrs.push(`${name}="${escapeXml(value)}"`);
|
|
736
|
+
}
|
|
737
|
+
function addBoolAttr(attrs, name, value) {
|
|
738
|
+
if (value !== void 0) attrs.push(`${name}="${value}"`);
|
|
739
|
+
}
|
|
740
|
+
function addOccursAttr(attrs, name, value) {
|
|
741
|
+
if (value !== void 0) attrs.push(`${name}="${value}"`);
|
|
742
|
+
}
|
|
743
|
+
function escapeXml(str) {
|
|
744
|
+
return str.replaceAll(/&/g, "&").replaceAll("<", "<").replaceAll(">", ">").replaceAll("\"", """).replaceAll("'", "'");
|
|
745
|
+
}
|
|
746
|
+
function buildElement$1(tag, attrs, children, ctx) {
|
|
747
|
+
const indent = ctx.pretty ? ctx.indent.repeat(ctx.level) : "";
|
|
748
|
+
const attrStr = attrs.length > 0 ? " " + attrs.join(" ") : "";
|
|
749
|
+
if (children.length === 0) return `${indent}<${tag}${attrStr}/>`;
|
|
750
|
+
const nl = ctx.pretty ? "\n" : "";
|
|
751
|
+
return `${indent}<${tag}${attrStr}>${nl}${children.join(nl)}${nl}${indent}</${tag}>`;
|
|
752
|
+
}
|
|
753
|
+
function buildElementWithText(tag, attrs, text, ctx) {
|
|
754
|
+
return `${ctx.pretty ? ctx.indent.repeat(ctx.level) : ""}<${tag}${attrs.length > 0 ? " " + attrs.join(" ") : ""}>${escapeXml(text)}</${tag}>`;
|
|
755
|
+
}
|
|
756
|
+
|
|
757
|
+
//#endregion
|
|
758
|
+
//#region src/xsd/helpers.ts
|
|
759
|
+
/**
|
|
760
|
+
* Resolve $imports for a schema by matching import schemaLocation to $filename.
|
|
761
|
+
*
|
|
762
|
+
* @param schema - The schema to resolve imports for
|
|
763
|
+
* @param availableSchemas - Array of schemas that may be imported
|
|
764
|
+
* @returns A new schema object with $imports populated
|
|
765
|
+
*
|
|
766
|
+
* @example
|
|
767
|
+
* ```typescript
|
|
768
|
+
* const orderSchema = parseXsd(orderXsd);
|
|
769
|
+
* const commonSchema = { ...parseXsd(commonXsd), $filename: 'common.xsd' };
|
|
770
|
+
*
|
|
771
|
+
* // orderSchema has: import: [{ schemaLocation: 'common.xsd', ... }]
|
|
772
|
+
* const resolved = resolveImports(orderSchema, [commonSchema]);
|
|
773
|
+
* // resolved.$imports = [commonSchema]
|
|
774
|
+
* ```
|
|
775
|
+
*/
|
|
776
|
+
function resolveImports(schema, availableSchemas) {
|
|
777
|
+
const imports = [];
|
|
778
|
+
if (schema.import) {
|
|
779
|
+
for (const imp of schema.import) if (imp.schemaLocation) {
|
|
780
|
+
const found = availableSchemas.find((s) => s.$filename === imp.schemaLocation);
|
|
781
|
+
if (found) imports.push(found);
|
|
782
|
+
}
|
|
783
|
+
}
|
|
784
|
+
return {
|
|
785
|
+
...schema,
|
|
786
|
+
$imports: imports
|
|
787
|
+
};
|
|
788
|
+
}
|
|
789
|
+
/**
|
|
790
|
+
* Resolve $imports for multiple schemas, linking them together.
|
|
791
|
+
*
|
|
792
|
+
* @param schemas - Array of schemas to link together
|
|
793
|
+
* @returns Array of schemas with $imports populated
|
|
794
|
+
*
|
|
795
|
+
* @example
|
|
796
|
+
* ```typescript
|
|
797
|
+
* const schemas = [
|
|
798
|
+
* { ...parseXsd(orderXsd), $filename: 'order.xsd' },
|
|
799
|
+
* { ...parseXsd(commonXsd), $filename: 'common.xsd' },
|
|
800
|
+
* ];
|
|
801
|
+
* const linked = linkSchemas(schemas);
|
|
802
|
+
* // Each schema now has $imports resolved
|
|
803
|
+
* ```
|
|
804
|
+
*/
|
|
805
|
+
function linkSchemas(schemas) {
|
|
806
|
+
return schemas.map((schema) => resolveImports(schema, schemas));
|
|
807
|
+
}
|
|
808
|
+
|
|
809
|
+
//#endregion
|
|
6
810
|
//#region src/walker/index.ts
|
|
7
811
|
/**
|
|
8
812
|
* Walk all complexTypes in a schema and its $imports/$includes (depth-first).
|
|
@@ -22,17 +826,19 @@ import { DOMImplementation, DOMParser, XMLSerializer } from "@xmldom/xmldom";
|
|
|
22
826
|
*/
|
|
23
827
|
function* walkComplexTypes(schema, options = {}) {
|
|
24
828
|
const complexTypes = schema.complexType;
|
|
25
|
-
if (complexTypes)
|
|
26
|
-
ct
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
ct
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
829
|
+
if (complexTypes) {
|
|
830
|
+
if (Array.isArray(complexTypes)) for (const ct of complexTypes) yield {
|
|
831
|
+
ct,
|
|
832
|
+
schema
|
|
833
|
+
};
|
|
834
|
+
else for (const [name, ct] of Object.entries(complexTypes)) yield {
|
|
835
|
+
ct: {
|
|
836
|
+
...ct,
|
|
837
|
+
name
|
|
838
|
+
},
|
|
839
|
+
schema
|
|
840
|
+
};
|
|
841
|
+
}
|
|
36
842
|
if (schema.redefine) {
|
|
37
843
|
for (const redef of schema.redefine) if (redef.complexType) for (const ct of redef.complexType) yield {
|
|
38
844
|
ct,
|
|
@@ -53,17 +859,19 @@ function* walkComplexTypes(schema, options = {}) {
|
|
|
53
859
|
*/
|
|
54
860
|
function* walkSimpleTypes(schema, options = {}) {
|
|
55
861
|
const simpleTypes = schema.simpleType;
|
|
56
|
-
if (simpleTypes)
|
|
57
|
-
st
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
st
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
862
|
+
if (simpleTypes) {
|
|
863
|
+
if (Array.isArray(simpleTypes)) for (const st of simpleTypes) yield {
|
|
864
|
+
st,
|
|
865
|
+
schema
|
|
866
|
+
};
|
|
867
|
+
else for (const [name, st] of Object.entries(simpleTypes)) yield {
|
|
868
|
+
st: {
|
|
869
|
+
...st,
|
|
870
|
+
name
|
|
871
|
+
},
|
|
872
|
+
schema
|
|
873
|
+
};
|
|
874
|
+
}
|
|
67
875
|
if (schema.redefine) {
|
|
68
876
|
for (const redef of schema.redefine) if (redef.simpleType) for (const st of redef.simpleType) yield {
|
|
69
877
|
st,
|
|
@@ -357,12 +1165,51 @@ function isArray(item) {
|
|
|
357
1165
|
if (typeof item.maxOccurs === "number") return item.maxOccurs > 1;
|
|
358
1166
|
if (typeof item.maxOccurs === "string") {
|
|
359
1167
|
if (item.maxOccurs === "unbounded") return true;
|
|
360
|
-
const num = parseInt(item.maxOccurs, 10);
|
|
361
|
-
return !isNaN(num) && num > 1;
|
|
1168
|
+
const num = Number.parseInt(item.maxOccurs, 10);
|
|
1169
|
+
return !Number.isNaN(num) && num > 1;
|
|
362
1170
|
}
|
|
363
1171
|
return false;
|
|
364
1172
|
}
|
|
365
1173
|
/**
|
|
1174
|
+
* Check whether a complexType permits wildcard child elements (xs:any).
|
|
1175
|
+
* Handles sequence/choice/all, nested groups, group references,
|
|
1176
|
+
* and complexContent extension/restriction (including base types).
|
|
1177
|
+
*/
|
|
1178
|
+
function hasWildcard(ct, schema) {
|
|
1179
|
+
const seenTypes = /* @__PURE__ */ new Set();
|
|
1180
|
+
const seenGroupRefs = /* @__PURE__ */ new Set();
|
|
1181
|
+
const groupsHaveAny = (...groups) => groups.some(groupHasAny);
|
|
1182
|
+
function namedGroupHasAny(ref) {
|
|
1183
|
+
if (!ref || seenGroupRefs.has(ref)) return false;
|
|
1184
|
+
seenGroupRefs.add(ref);
|
|
1185
|
+
const named = findGroup(stripNsPrefix(ref), schema);
|
|
1186
|
+
if (!named) return false;
|
|
1187
|
+
return groupsHaveAny(named.sequence, named.choice, named.all);
|
|
1188
|
+
}
|
|
1189
|
+
function groupHasAny(group) {
|
|
1190
|
+
if (!group) return false;
|
|
1191
|
+
if (group.any && group.any.length > 0) return true;
|
|
1192
|
+
if ([...group.sequence ?? [], ...group.choice ?? []].some(groupHasAny)) return true;
|
|
1193
|
+
return (group.group ?? []).some((ref) => namedGroupHasAny(ref.ref));
|
|
1194
|
+
}
|
|
1195
|
+
function extHasAny(current) {
|
|
1196
|
+
const ext = current.complexContent?.extension ?? current.complexContent?.restriction;
|
|
1197
|
+
if (!ext) return false;
|
|
1198
|
+
if (groupsHaveAny(ext.sequence, ext.choice, ext.all)) return true;
|
|
1199
|
+
if (namedGroupHasAny(ext.group?.ref)) return true;
|
|
1200
|
+
if (!ext.base) return false;
|
|
1201
|
+
const baseEntry = findComplexType(stripNsPrefix(ext.base), schema);
|
|
1202
|
+
return baseEntry ? visit(baseEntry.ct) : false;
|
|
1203
|
+
}
|
|
1204
|
+
function visit(current) {
|
|
1205
|
+
if (seenTypes.has(current)) return false;
|
|
1206
|
+
seenTypes.add(current);
|
|
1207
|
+
if (groupsHaveAny(current.sequence, current.choice, current.all)) return true;
|
|
1208
|
+
return extHasAny(current) || namedGroupHasAny(current.group?.ref);
|
|
1209
|
+
}
|
|
1210
|
+
return visit(ct);
|
|
1211
|
+
}
|
|
1212
|
+
/**
|
|
366
1213
|
* Check if an element is abstract
|
|
367
1214
|
*/
|
|
368
1215
|
function isAbstractElement(element) {
|
|
@@ -488,18 +1335,8 @@ function parseElement(node, typeDef, schema, rootSchema) {
|
|
|
488
1335
|
for (const { element, array } of walkElements(typeDef, schema)) {
|
|
489
1336
|
const resolved = resolveElementInfo$1(element, schema);
|
|
490
1337
|
if (!resolved) continue;
|
|
491
|
-
if (isAbstractElement$1(resolved.name, rootSchema))
|
|
492
|
-
|
|
493
|
-
const allChildren = getAllChildElements(node);
|
|
494
|
-
for (const child of allChildren) {
|
|
495
|
-
const childName = getLocalName(child);
|
|
496
|
-
const substitute = substitutes.find((s) => s.element.name === childName);
|
|
497
|
-
if (substitute && substitute.element.name) {
|
|
498
|
-
const subTypeName = substitute.element.type ? stripNsPrefix(substitute.element.type) : void 0;
|
|
499
|
-
result[substitute.element.name] = parseChildValue(child, subTypeName, substitute.schema, rootSchema);
|
|
500
|
-
}
|
|
501
|
-
}
|
|
502
|
-
} else {
|
|
1338
|
+
if (isAbstractElement$1(resolved.name, rootSchema)) parseSubstitutionChildren(node, resolved.name, rootSchema, result);
|
|
1339
|
+
else {
|
|
503
1340
|
const children = getChildElements(node, resolved.name);
|
|
504
1341
|
if (array || children.length > 1) {
|
|
505
1342
|
const values = children.map((child) => parseChildValue(child, resolved.typeName, schema, rootSchema));
|
|
@@ -507,6 +1344,67 @@ function parseElement(node, typeDef, schema, rootSchema) {
|
|
|
507
1344
|
} else if (children.length === 1) result[resolved.name] = parseChildValue(children[0], resolved.typeName, schema, rootSchema);
|
|
508
1345
|
}
|
|
509
1346
|
}
|
|
1347
|
+
if (hasWildcard(typeDef, schema)) parseWildcardChildren(node, result);
|
|
1348
|
+
return result;
|
|
1349
|
+
}
|
|
1350
|
+
/**
|
|
1351
|
+
* Parse children that substitute for an abstract element — substitutes can
|
|
1352
|
+
* live in any imported schema, so lookups use the root schema.
|
|
1353
|
+
*/
|
|
1354
|
+
function parseSubstitutionChildren(node, headName, rootSchema, result) {
|
|
1355
|
+
const substitutes = findSubstitutingElements(headName, rootSchema);
|
|
1356
|
+
for (const child of getAllChildElements(node)) {
|
|
1357
|
+
const childName = getLocalName(child);
|
|
1358
|
+
const substitute = substitutes.find((s) => s.element.name === childName);
|
|
1359
|
+
if (substitute && substitute.element.name) {
|
|
1360
|
+
const subTypeName = substitute.element.type ? stripNsPrefix(substitute.element.type) : void 0;
|
|
1361
|
+
result[substitute.element.name] = parseChildValue(child, subTypeName, substitute.schema, rootSchema);
|
|
1362
|
+
}
|
|
1363
|
+
}
|
|
1364
|
+
}
|
|
1365
|
+
/**
|
|
1366
|
+
* Collect wildcard (xs:any) children under their qualified tag names.
|
|
1367
|
+
* Repeated sibling names become arrays.
|
|
1368
|
+
*/
|
|
1369
|
+
function parseWildcardChildren(node, result) {
|
|
1370
|
+
const seen = /* @__PURE__ */ new Set();
|
|
1371
|
+
for (const child of getAllChildElements(node)) {
|
|
1372
|
+
const name = child.tagName;
|
|
1373
|
+
if (result[name] !== void 0 || seen.has(name)) continue;
|
|
1374
|
+
seen.add(name);
|
|
1375
|
+
const same = getAllChildElements(node).filter((c) => c.tagName === name);
|
|
1376
|
+
result[name] = same.length > 1 ? same.map(parseAnyValue) : parseAnyValue(child);
|
|
1377
|
+
}
|
|
1378
|
+
}
|
|
1379
|
+
/**
|
|
1380
|
+
* Parse a wildcard (xs:any) element generically:
|
|
1381
|
+
* leaf elements become strings, element children become nested records,
|
|
1382
|
+
* repeated names become arrays. Attributes are preserved under `@name`
|
|
1383
|
+
* keys (including xmlns:* for namespace round-trips) and text content of
|
|
1384
|
+
* attributed elements under `_text`. Qualified tag names keep their
|
|
1385
|
+
* namespace prefixes so prefixed children round-trip faithfully.
|
|
1386
|
+
*/
|
|
1387
|
+
function parseAnyValue(node) {
|
|
1388
|
+
const result = {};
|
|
1389
|
+
for (let i = 0; i < node.attributes.length; i++) {
|
|
1390
|
+
const attr = node.attributes[i];
|
|
1391
|
+
result[`@${attr.name}`] = attr.value;
|
|
1392
|
+
}
|
|
1393
|
+
const children = getAllChildElements(node);
|
|
1394
|
+
if (children.length === 0) {
|
|
1395
|
+
if (Object.keys(result).length === 0) return getTextContent(node);
|
|
1396
|
+
const text = getTextContent(node);
|
|
1397
|
+
if (text) result._text = text;
|
|
1398
|
+
return result;
|
|
1399
|
+
}
|
|
1400
|
+
for (const child of children) {
|
|
1401
|
+
const name = child.tagName;
|
|
1402
|
+
const value = parseAnyValue(child);
|
|
1403
|
+
const existing = result[name];
|
|
1404
|
+
if (existing === void 0) result[name] = value;
|
|
1405
|
+
else if (Array.isArray(existing)) existing.push(value);
|
|
1406
|
+
else result[name] = [existing, value];
|
|
1407
|
+
}
|
|
510
1408
|
return result;
|
|
511
1409
|
}
|
|
512
1410
|
/**
|
|
@@ -863,7 +1761,8 @@ function findMatchingElement(data, schema) {
|
|
|
863
1761
|
let ctSchema = searchSchema;
|
|
864
1762
|
if (element.complexType) ct = element.complexType;
|
|
865
1763
|
else if (element.type) {
|
|
866
|
-
const
|
|
1764
|
+
const typeName = stripNsPrefix(element.type);
|
|
1765
|
+
const typeEntry = findComplexType(typeName, searchSchema);
|
|
867
1766
|
if (typeEntry) {
|
|
868
1767
|
ct = typeEntry.ct;
|
|
869
1768
|
ctSchema = typeEntry.schema;
|
|
@@ -908,8 +1807,23 @@ function findMatchingElement(data, schema) {
|
|
|
908
1807
|
* @param rootSchema - The original schema passed to build(), used for substitution group lookup
|
|
909
1808
|
*/
|
|
910
1809
|
function buildElement(doc, node, data, typeDef, schema, rootSchema, prefix) {
|
|
1810
|
+
const wildcard = hasWildcard(typeDef, schema);
|
|
1811
|
+
const consumed = /* @__PURE__ */ new Set();
|
|
1812
|
+
buildAttributes(node, data, typeDef, schema, rootSchema, consumed);
|
|
1813
|
+
buildDeclaredElements(doc, node, data, typeDef, schema, rootSchema, prefix, consumed);
|
|
1814
|
+
if (wildcard) for (const key of Object.keys(data)) {
|
|
1815
|
+
if (consumed.has(key)) continue;
|
|
1816
|
+
buildAnyField(doc, node, key, data[key]);
|
|
1817
|
+
}
|
|
1818
|
+
}
|
|
1819
|
+
/**
|
|
1820
|
+
* Build declared attributes from the type definition (walker handles
|
|
1821
|
+
* inheritance). Adds each declared attribute name to `consumed`.
|
|
1822
|
+
*/
|
|
1823
|
+
function buildAttributes(node, data, typeDef, schema, rootSchema, consumed) {
|
|
911
1824
|
for (const { attribute, schema: attrSchema } of walkAttributes(typeDef, schema)) {
|
|
912
1825
|
if (!attribute.name) continue;
|
|
1826
|
+
consumed.add(attribute.name);
|
|
913
1827
|
const value = data[attribute.name];
|
|
914
1828
|
if (value !== void 0 && value !== null) {
|
|
915
1829
|
const attributeFormDefault = attrSchema.attributeFormDefault;
|
|
@@ -922,28 +1836,63 @@ function buildElement(doc, node, data, typeDef, schema, rootSchema, prefix) {
|
|
|
922
1836
|
node.setAttribute(attrName, formatValue(value, attribute.type || "string"));
|
|
923
1837
|
}
|
|
924
1838
|
}
|
|
1839
|
+
}
|
|
1840
|
+
/**
|
|
1841
|
+
* Build declared child elements via the walker (handles inheritance,
|
|
1842
|
+
* groups, refs, substitution). Adds each declared key to `consumed`.
|
|
1843
|
+
*/
|
|
1844
|
+
function buildDeclaredElements(doc, node, data, typeDef, schema, rootSchema, prefix, consumed) {
|
|
925
1845
|
for (const { element, schema: elementDefSchema } of walkElements(typeDef, schema)) {
|
|
926
1846
|
if (element.ref) {
|
|
927
1847
|
const refName = stripNsPrefix(element.ref);
|
|
928
1848
|
const refElement = findElement(refName, elementDefSchema);
|
|
929
1849
|
if (refElement && refElement.element.abstract) {
|
|
930
|
-
|
|
931
|
-
for (const substitute of substitutes) {
|
|
932
|
-
const subName = substitute.element.name;
|
|
933
|
-
if (!subName) continue;
|
|
934
|
-
const value = data[subName];
|
|
935
|
-
if (value !== void 0) buildField(doc, node, value, subName, substitute.element.type ? stripNsPrefix(substitute.element.type) : void 0, substitute.schema, rootSchema, prefix);
|
|
936
|
-
}
|
|
1850
|
+
buildSubstituteElements(doc, node, data, refName, rootSchema, prefix, consumed);
|
|
937
1851
|
continue;
|
|
938
1852
|
}
|
|
939
1853
|
}
|
|
940
1854
|
const resolved = resolveElementInfo(element, elementDefSchema);
|
|
941
1855
|
if (!resolved) continue;
|
|
1856
|
+
consumed.add(resolved.dataKey);
|
|
942
1857
|
const value = data[resolved.dataKey];
|
|
943
|
-
if (value
|
|
1858
|
+
if (value != null) buildFieldWithTagName(doc, node, value, resolved.tagName, resolved.typeName, resolved.inlineComplexType, resolved.elementSchema, rootSchema, prefix, resolved.form);
|
|
944
1859
|
}
|
|
945
1860
|
}
|
|
946
1861
|
/**
|
|
1862
|
+
* Build elements that substitute for an abstract element — substitutes can
|
|
1863
|
+
* live in any imported schema, so lookups use the root schema. Adds each
|
|
1864
|
+
* emitted key to `consumed`.
|
|
1865
|
+
*/
|
|
1866
|
+
function buildSubstituteElements(doc, node, data, refName, rootSchema, prefix, consumed) {
|
|
1867
|
+
const substitutes = findSubstitutes$1(refName, rootSchema);
|
|
1868
|
+
for (const substitute of substitutes) {
|
|
1869
|
+
const subName = substitute.element.name;
|
|
1870
|
+
if (!subName) continue;
|
|
1871
|
+
consumed.add(subName);
|
|
1872
|
+
const value = data[subName];
|
|
1873
|
+
if (value != null) buildField(doc, node, value, subName, substitute.element.type ? stripNsPrefix(substitute.element.type) : void 0, substitute.schema, rootSchema, prefix);
|
|
1874
|
+
}
|
|
1875
|
+
}
|
|
1876
|
+
/**
|
|
1877
|
+
* Build a wildcard (xs:any) element generically:
|
|
1878
|
+
* primitives become text elements, objects become nested elements,
|
|
1879
|
+
* arrays become repeated sibling elements.
|
|
1880
|
+
*/
|
|
1881
|
+
function buildAnyField(doc, parent, tagName, value) {
|
|
1882
|
+
if (value === void 0 || value === null) return;
|
|
1883
|
+
if (Array.isArray(value)) {
|
|
1884
|
+
for (const item of value) buildAnyField(doc, parent, tagName, item);
|
|
1885
|
+
return;
|
|
1886
|
+
}
|
|
1887
|
+
const el = doc.createElement(tagName);
|
|
1888
|
+
if (typeof value === "object") for (const [key, nested] of Object.entries(value)) if (key.startsWith("@")) {
|
|
1889
|
+
if (nested !== void 0 && nested !== null) el.setAttribute(key.slice(1), String(nested));
|
|
1890
|
+
} else if (key === "_text") el.textContent = String(nested ?? "");
|
|
1891
|
+
else buildAnyField(doc, el, key, nested);
|
|
1892
|
+
else el.textContent = String(value);
|
|
1893
|
+
parent.appendChild(el);
|
|
1894
|
+
}
|
|
1895
|
+
/**
|
|
947
1896
|
* Resolve element info (name and type), handling ref
|
|
948
1897
|
*
|
|
949
1898
|
* Returns:
|
|
@@ -992,7 +1941,6 @@ function resolveElementInfo(element, schema) {
|
|
|
992
1941
|
* - "unqualified" (default): local elements do NOT get namespace prefix
|
|
993
1942
|
*/
|
|
994
1943
|
function buildField(doc, parent, value, elementName, typeName, schema, rootSchema, prefix) {
|
|
995
|
-
if (value === void 0 || value === null) return;
|
|
996
1944
|
const nestedType = typeName ? findComplexType(typeName, schema) : void 0;
|
|
997
1945
|
const usePrefix = rootSchema.elementFormDefault === "qualified" ? prefix : void 0;
|
|
998
1946
|
const tagName = usePrefix ? `${usePrefix}:${elementName}` : elementName;
|
|
@@ -1024,7 +1972,6 @@ function buildField(doc, parent, value, elementName, typeName, schema, rootSchem
|
|
|
1024
1972
|
* 3. Direct elements - apply elementFormDefault logic
|
|
1025
1973
|
*/
|
|
1026
1974
|
function buildFieldWithTagName(doc, parent, value, tagName, typeName, inlineComplexType, elementSchema, rootSchema, prefix, elementForm) {
|
|
1027
|
-
if (value === void 0 || value === null) return;
|
|
1028
1975
|
let nestedType;
|
|
1029
1976
|
if (inlineComplexType) nestedType = {
|
|
1030
1977
|
ct: inlineComplexType,
|
|
@@ -1112,5 +2059,5 @@ function typedSchema(schema) {
|
|
|
1112
2059
|
}
|
|
1113
2060
|
|
|
1114
2061
|
//#endregion
|
|
1115
|
-
export { SchemaResolver, SchemaTraverser, build as buildXml, buildXsd, createSchemaLoader, defaultLoader, defineConfig, deriveRootTypeName, findComplexType, findElement, findSimpleType, findSubstitutes, generateInterfaces, generateSchemaFile, generateSchemaLiteral, getSubstitutes, isAbstractElement, linkSchema, linkSchemas, loadAndLinkSchema, loadSchema, parseXsd as parse, parseXsd, parseSchemaContent, parse as parseXml, resolveImports, resolveSchema, resolveSchemaTypes, runCodegen, stripNsPrefix, typedSchema, walkAttributes, walkComplexTypes, walkElements, walkSimpleTypes, walkTopLevelElements };
|
|
2062
|
+
export { SchemaResolver, SchemaTraverser, build as buildXml, buildXsd, createSchemaLoader, defaultLoader, defineConfig, deriveRootTypeName, findComplexType, findElement, findSimpleType, findSubstitutes, generateInterfaces, generateSchemaFile, generateSchemaLiteral, getSubstitutes, hasWildcard, isAbstractElement, linkSchema, linkSchemas, loadAndLinkSchema, loadSchema, parseXsd as parse, parseXsd, parseSchemaContent, parse as parseXml, resolveImports, resolveSchema, resolveSchemaTypes, runCodegen, stripNsPrefix, typedSchema, walkAttributes, walkComplexTypes, walkElements, walkSimpleTypes, walkTopLevelElements };
|
|
1116
2063
|
//# sourceMappingURL=index.mjs.map
|