@ai-sdk-tool/rxml 0.1.0 → 0.1.1

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/dist/index.cjs CHANGED
@@ -27,16 +27,19 @@ __export(index_exports, {
27
27
  RXMLStringifyError: () => RXMLStringifyError,
28
28
  XMLTokenizer: () => XMLTokenizer,
29
29
  XMLTransformStream: () => XMLTransformStream,
30
+ coerceBySchema: () => coerceBySchema,
30
31
  coerceDomBySchema: () => coerceDomBySchema,
31
32
  countTagOccurrences: () => countTagOccurrences,
32
33
  createXMLStream: () => createXMLStream,
33
34
  domToObject: () => domToObject,
34
35
  extractRawInner: () => extractRawInner,
35
36
  filter: () => filter,
37
+ findAllTopLevelRanges: () => findAllTopLevelRanges,
36
38
  findElementByIdStream: () => findElementByIdStream,
37
39
  findElementsByClassStream: () => findElementsByClassStream,
38
40
  findFirstTopLevelRange: () => findFirstTopLevelRange,
39
41
  getPropertySchema: () => getPropertySchema,
42
+ getSchemaType: () => getSchemaType,
40
43
  getStringTypedProperties: () => getStringTypedProperties,
41
44
  parse: () => parse,
42
45
  parseFromStream: () => parseFromStream,
@@ -49,7 +52,9 @@ __export(index_exports, {
49
52
  stringify: () => stringify,
50
53
  stringifyNode: () => stringifyNode,
51
54
  stringifyNodes: () => stringifyNodes,
52
- toContentString: () => toContentString
55
+ toContentString: () => toContentString,
56
+ unescapeXml: () => unescapeXml,
57
+ unwrapJsonSchema: () => unwrapJsonSchema
53
58
  });
54
59
  module.exports = __toCommonJS(index_exports);
55
60
 
@@ -395,22 +400,33 @@ function coerceDomBySchema(domObject, schema) {
395
400
  }
396
401
  }
397
402
  function getStringTypedProperties(schema) {
398
- const set = /* @__PURE__ */ new Set();
399
- const unwrapped = unwrapJsonSchema(schema);
400
- if (unwrapped && typeof unwrapped === "object") {
403
+ const collected = /* @__PURE__ */ new Set();
404
+ const visit = (s) => {
405
+ const unwrapped = unwrapJsonSchema(s);
406
+ if (!unwrapped || typeof unwrapped !== "object") return;
401
407
  const u = unwrapped;
402
- const props = u.properties;
403
- if (props && typeof props === "object") {
404
- for (const key of Object.keys(props)) {
405
- const propSchema = props[key];
406
- const propType = getSchemaType(propSchema);
407
- if (propType === "string") {
408
- set.add(key);
408
+ const type = getSchemaType(unwrapped);
409
+ if (type === "object") {
410
+ const props = u.properties;
411
+ if (props && typeof props === "object") {
412
+ for (const [key, propSchema] of Object.entries(props)) {
413
+ const t = getSchemaType(propSchema);
414
+ if (t === "string") {
415
+ collected.add(key);
416
+ } else if (t === "object" || t === "array") {
417
+ visit(propSchema);
418
+ }
409
419
  }
410
420
  }
421
+ } else if (type === "array") {
422
+ const items = u.items;
423
+ if (items) visit(items);
424
+ const prefix = u.prefixItems;
425
+ if (Array.isArray(prefix)) prefix.forEach(visit);
411
426
  }
412
- }
413
- return set;
427
+ };
428
+ visit(schema);
429
+ return collected;
414
430
  }
415
431
  function processArrayContent(value, schema, textNodeName) {
416
432
  if (!Array.isArray(value)) return value;
@@ -554,6 +570,9 @@ function escapeXmlMinimalAttr(value, wrapper = '"') {
554
570
  }
555
571
  return escaped;
556
572
  }
573
+ function unescapeXml(text) {
574
+ return text.replace(/&lt;/g, "<").replace(/&gt;/g, ">").replace(/&quot;/g, '"').replace(/&apos;/g, "'").replace(/&amp;/g, "&");
575
+ }
557
576
 
558
577
  // src/schema/extraction.ts
559
578
  function extractRawInner(xmlContent, tagName) {
@@ -571,6 +590,11 @@ function extractRawInner(xmlContent, tagName) {
571
590
  if (i >= len) return void 0;
572
591
  const ch = xmlContent[i];
573
592
  if (ch === "!") {
593
+ if (xmlContent.startsWith("!DOCTYPE", i + 1)) {
594
+ const gt2 = xmlContent.indexOf(">", i + 1);
595
+ i = gt2 === -1 ? len : gt2 + 1;
596
+ continue;
597
+ }
574
598
  if (xmlContent.startsWith("!--", i + 1)) {
575
599
  const close = xmlContent.indexOf("-->", i + 4);
576
600
  i = close === -1 ? len : close + 3;
@@ -635,6 +659,11 @@ function extractRawInner(xmlContent, tagName) {
635
659
  if (nx >= len) break;
636
660
  const h = xmlContent[nx];
637
661
  if (h === "!") {
662
+ if (xmlContent.startsWith("!DOCTYPE", nx + 1)) {
663
+ const gt22 = xmlContent.indexOf(">", nx + 1);
664
+ pos = gt22 === -1 ? len : gt22 + 1;
665
+ continue;
666
+ }
638
667
  if (xmlContent.startsWith("!--", nx + 1)) {
639
668
  const close = xmlContent.indexOf("-->", nx + 4);
640
669
  pos = close === -1 ? len : close + 3;
@@ -715,6 +744,155 @@ function extractRawInner(xmlContent, tagName) {
715
744
  }
716
745
  return void 0;
717
746
  }
747
+ function findAllInnerRanges(xmlContent, tagName) {
748
+ const len = xmlContent.length;
749
+ const target = tagName;
750
+ const ranges = [];
751
+ let i = 0;
752
+ while (i < len) {
753
+ const lt = xmlContent.indexOf("<", i);
754
+ if (lt === -1) break;
755
+ i = lt + 1;
756
+ if (i >= len) break;
757
+ const ch = xmlContent[i];
758
+ if (ch === "!") {
759
+ if (xmlContent.startsWith("!--", i + 1)) {
760
+ const close = xmlContent.indexOf("-->", i + 4);
761
+ i = close === -1 ? len : close + 3;
762
+ continue;
763
+ }
764
+ if (xmlContent.startsWith("![CDATA[", i + 1)) {
765
+ const close = xmlContent.indexOf("]]>", i + 9);
766
+ i = close === -1 ? len : close + 3;
767
+ continue;
768
+ }
769
+ const gt = xmlContent.indexOf(">", i + 1);
770
+ i = gt === -1 ? len : gt + 1;
771
+ continue;
772
+ }
773
+ if (ch === "?") {
774
+ const close = xmlContent.indexOf("?>", i + 1);
775
+ i = close === -1 ? len : close + 2;
776
+ continue;
777
+ }
778
+ if (ch === "/") {
779
+ const gt = xmlContent.indexOf(">", i + 1);
780
+ i = gt === -1 ? len : gt + 1;
781
+ continue;
782
+ }
783
+ let j = i;
784
+ if (j < len && isNameStartChar(xmlContent[j])) {
785
+ j++;
786
+ while (j < len && isNameChar(xmlContent[j])) j++;
787
+ }
788
+ const name = xmlContent.slice(i, j);
789
+ let k = j;
790
+ let isSelfClosing = false;
791
+ while (k < len) {
792
+ const c = xmlContent[k];
793
+ if (c === '"' || c === "'") {
794
+ k = skipQuoted(xmlContent, k);
795
+ continue;
796
+ }
797
+ if (c === ">") break;
798
+ if (c === "/" && xmlContent[k + 1] === ">") {
799
+ isSelfClosing = true;
800
+ k++;
801
+ break;
802
+ }
803
+ k++;
804
+ }
805
+ const tagEnd = k;
806
+ if (name !== target) {
807
+ i = xmlContent[tagEnd] === ">" ? tagEnd + 1 : tagEnd + 1;
808
+ continue;
809
+ }
810
+ const contentStart = xmlContent[tagEnd] === ">" ? tagEnd + 1 : tagEnd + 1;
811
+ if (isSelfClosing) {
812
+ ranges.push({ start: contentStart, end: contentStart });
813
+ i = contentStart;
814
+ continue;
815
+ }
816
+ let pos = contentStart;
817
+ let sameDepth = 1;
818
+ while (pos < len) {
819
+ const nextLt = xmlContent.indexOf("<", pos);
820
+ if (nextLt === -1) break;
821
+ const nx = nextLt + 1;
822
+ if (nx >= len) break;
823
+ const h = xmlContent[nx];
824
+ if (h === "!") {
825
+ if (xmlContent.startsWith("!--", nx + 1)) {
826
+ const close = xmlContent.indexOf("-->", nx + 4);
827
+ pos = close === -1 ? len : close + 3;
828
+ continue;
829
+ }
830
+ if (xmlContent.startsWith("![CDATA[", nx + 1)) {
831
+ const close = xmlContent.indexOf("]]>", nx + 9);
832
+ pos = close === -1 ? len : close + 3;
833
+ continue;
834
+ }
835
+ const gt2 = xmlContent.indexOf(">", nx + 1);
836
+ pos = gt2 === -1 ? len : gt2 + 1;
837
+ continue;
838
+ } else if (h === "?") {
839
+ const close = xmlContent.indexOf("?>", nx + 1);
840
+ pos = close === -1 ? len : close + 2;
841
+ continue;
842
+ } else if (h === "/") {
843
+ let t = nx + 1;
844
+ if (t < len && isNameStartChar(xmlContent[t])) {
845
+ t++;
846
+ while (t < len && isNameChar(xmlContent[t])) t++;
847
+ }
848
+ const endName = xmlContent.slice(nx + 1, t);
849
+ const gt2 = xmlContent.indexOf(">", t);
850
+ if (endName === target) {
851
+ sameDepth--;
852
+ if (sameDepth === 0) {
853
+ ranges.push({ start: contentStart, end: nextLt });
854
+ i = gt2 === -1 ? len : gt2 + 1;
855
+ break;
856
+ }
857
+ }
858
+ pos = gt2 === -1 ? len : gt2 + 1;
859
+ continue;
860
+ } else {
861
+ let t = nx;
862
+ if (t < len && isNameStartChar(xmlContent[t])) {
863
+ t++;
864
+ while (t < len && isNameChar(xmlContent[t])) t++;
865
+ }
866
+ let u = t;
867
+ let isSelfClosingNested = false;
868
+ while (u < len) {
869
+ const cu = xmlContent[u];
870
+ if (cu === '"' || cu === "'") {
871
+ u = skipQuoted(xmlContent, u);
872
+ continue;
873
+ }
874
+ if (cu === ">") break;
875
+ if (cu === "/" && xmlContent[u + 1] === ">") {
876
+ isSelfClosingNested = true;
877
+ u++;
878
+ break;
879
+ }
880
+ u++;
881
+ }
882
+ const startName = xmlContent.slice(nx, t);
883
+ if (startName === target && !isSelfClosingNested) {
884
+ sameDepth++;
885
+ }
886
+ pos = xmlContent[u] === ">" ? u + 1 : u + 1;
887
+ continue;
888
+ }
889
+ }
890
+ if (sameDepth !== 0) {
891
+ break;
892
+ }
893
+ }
894
+ return ranges;
895
+ }
718
896
  function findFirstTopLevelRange(xmlContent, tagName) {
719
897
  const len = xmlContent.length;
720
898
  const target = tagName;
@@ -727,6 +905,11 @@ function findFirstTopLevelRange(xmlContent, tagName) {
727
905
  if (i >= len) return void 0;
728
906
  const ch = xmlContent[i];
729
907
  if (ch === "!") {
908
+ if (xmlContent.startsWith("!DOCTYPE", i + 1)) {
909
+ const gt2 = xmlContent.indexOf(">", i + 1);
910
+ i = gt2 === -1 ? len : gt2 + 1;
911
+ continue;
912
+ }
730
913
  if (xmlContent.startsWith("!--", i + 1)) {
731
914
  const close = xmlContent.indexOf("-->", i + 4);
732
915
  i = close === -1 ? len : close + 3;
@@ -785,6 +968,11 @@ function findFirstTopLevelRange(xmlContent, tagName) {
785
968
  if (nx >= len) break;
786
969
  const h = xmlContent[nx];
787
970
  if (h === "!") {
971
+ if (xmlContent.startsWith("!DOCTYPE", nx + 1)) {
972
+ const gt22 = xmlContent.indexOf(">", nx + 1);
973
+ pos = gt22 === -1 ? len : gt22 + 1;
974
+ continue;
975
+ }
788
976
  if (xmlContent.startsWith("!--", nx + 1)) {
789
977
  const close = xmlContent.indexOf("-->", nx + 4);
790
978
  pos = close === -1 ? len : close + 3;
@@ -932,6 +1120,101 @@ function countTagOccurrences(xmlContent, tagName, excludeRanges, shouldSkipFirst
932
1120
  }
933
1121
  return count;
934
1122
  }
1123
+ function findAllTopLevelRanges(xmlContent, tagName) {
1124
+ const ranges = [];
1125
+ const len = xmlContent.length;
1126
+ const target = tagName;
1127
+ let i = 0;
1128
+ let depth = 0;
1129
+ while (i < len) {
1130
+ const lt = xmlContent.indexOf("<", i);
1131
+ if (lt === -1) break;
1132
+ i = lt + 1;
1133
+ if (i >= len) break;
1134
+ const ch = xmlContent[i];
1135
+ if (ch === "!") {
1136
+ if (xmlContent.startsWith("!DOCTYPE", i + 1)) {
1137
+ const gt2 = xmlContent.indexOf(">", i + 1);
1138
+ i = gt2 === -1 ? len : gt2 + 1;
1139
+ continue;
1140
+ }
1141
+ if (xmlContent.startsWith("!--", i + 1)) {
1142
+ const close = xmlContent.indexOf("-->", i + 4);
1143
+ i = close === -1 ? len : close + 3;
1144
+ continue;
1145
+ }
1146
+ if (xmlContent.startsWith("![CDATA[", i + 1)) {
1147
+ const close = xmlContent.indexOf("]]>", i + 9);
1148
+ i = close === -1 ? len : close + 3;
1149
+ continue;
1150
+ }
1151
+ const gt = xmlContent.indexOf(">", i + 1);
1152
+ i = gt === -1 ? len : gt + 1;
1153
+ continue;
1154
+ } else if (ch === "?") {
1155
+ const close = xmlContent.indexOf("?>", i + 1);
1156
+ i = close === -1 ? len : close + 2;
1157
+ continue;
1158
+ } else if (ch === "/") {
1159
+ i++;
1160
+ const { name: name2, newPos: newPos2 } = parseName(xmlContent, i);
1161
+ if (name2 === target) depth--;
1162
+ i = xmlContent.indexOf(">", newPos2);
1163
+ if (i === -1) break;
1164
+ i++;
1165
+ continue;
1166
+ }
1167
+ const { name, newPos } = parseName(xmlContent, i);
1168
+ i = newPos;
1169
+ let k = i;
1170
+ while (k < len && xmlContent[k] !== ">") {
1171
+ const c = xmlContent[k];
1172
+ if (c === '"' || c === "'") {
1173
+ k = skipQuoted(xmlContent, k);
1174
+ continue;
1175
+ }
1176
+ if (c === "/" && xmlContent[k + 1] === ">") {
1177
+ k++;
1178
+ break;
1179
+ }
1180
+ k++;
1181
+ }
1182
+ if (name === target && depth === 0) {
1183
+ const tagStart = lt;
1184
+ const isSelfClosing = xmlContent[k] === "/" || xmlContent.startsWith("/>", k);
1185
+ if (isSelfClosing) {
1186
+ ranges.push({
1187
+ start: tagStart,
1188
+ end: k + (xmlContent[k] === "/" ? 2 : 1)
1189
+ });
1190
+ } else {
1191
+ depth++;
1192
+ let closeDepth = 1;
1193
+ let j = k + 1;
1194
+ while (j < len && closeDepth > 0) {
1195
+ const nextLt = xmlContent.indexOf("<", j);
1196
+ if (nextLt === -1) break;
1197
+ if (xmlContent[nextLt + 1] === "/") {
1198
+ const { name: closeName } = parseName(xmlContent, nextLt + 2);
1199
+ if (closeName === target) closeDepth--;
1200
+ } else if (xmlContent[nextLt + 1] !== "!" && xmlContent[nextLt + 1] !== "?") {
1201
+ const { name: openName } = parseName(xmlContent, nextLt + 1);
1202
+ if (openName === target) closeDepth++;
1203
+ }
1204
+ j = xmlContent.indexOf(">", nextLt + 1);
1205
+ if (j === -1) break;
1206
+ j++;
1207
+ }
1208
+ if (closeDepth === 0) {
1209
+ ranges.push({ start: tagStart, end: j });
1210
+ }
1211
+ depth--;
1212
+ }
1213
+ }
1214
+ i = k + 1;
1215
+ }
1216
+ return ranges;
1217
+ }
935
1218
 
936
1219
  // src/core/tokenizer.ts
937
1220
  var XMLTokenizer = class {
@@ -1183,6 +1466,30 @@ var XMLTokenizer = class {
1183
1466
  };
1184
1467
 
1185
1468
  // src/core/parser.ts
1469
+ function deepDecodeStringsBySchema(input, schema) {
1470
+ var _a;
1471
+ if (input == null || schema == null) return input;
1472
+ const type = getSchemaType(schema);
1473
+ if (type === "string" && typeof input === "string") {
1474
+ return unescapeXml(input);
1475
+ }
1476
+ if (type === "array" && Array.isArray(input)) {
1477
+ const unwrapped = unwrapJsonSchema(schema);
1478
+ const itemSchema = (_a = unwrapped == null ? void 0 : unwrapped.items) != null ? _a : {};
1479
+ return input.map((item) => deepDecodeStringsBySchema(item, itemSchema));
1480
+ }
1481
+ if (type === "object" && input && typeof input === "object") {
1482
+ const obj = input;
1483
+ const out = {};
1484
+ for (const key of Object.keys(obj)) {
1485
+ const childSchema = getPropertySchema(schema, key);
1486
+ out[key] = deepDecodeStringsBySchema(obj[key], childSchema);
1487
+ }
1488
+ return out;
1489
+ }
1490
+ if (typeof input === "string") return unescapeXml(input);
1491
+ return input;
1492
+ }
1186
1493
  function parse(xmlInner, schema, options = {}) {
1187
1494
  var _a, _b, _c;
1188
1495
  const textNodeName = (_a = options.textNodeName) != null ? _a : "#text";
@@ -1248,11 +1555,25 @@ function parse(xmlInner, schema, options = {}) {
1248
1555
  }
1249
1556
  }
1250
1557
  }
1251
- const stringTypedProps = getStringTypedProperties(schema);
1558
+ const getTopLevelStringProps = (s) => {
1559
+ const set = /* @__PURE__ */ new Set();
1560
+ const unwrapped = unwrapJsonSchema(s);
1561
+ if (unwrapped && typeof unwrapped === "object") {
1562
+ const props = unwrapped.properties;
1563
+ if (props && typeof props === "object") {
1564
+ for (const [k, v] of Object.entries(props)) {
1565
+ if (getSchemaType(v) === "string") set.add(k);
1566
+ }
1567
+ }
1568
+ }
1569
+ return set;
1570
+ };
1571
+ const topLevelStringProps = getTopLevelStringProps(schema);
1572
+ const deepStringTypedProps = getStringTypedProperties(schema);
1252
1573
  const duplicateKeys = /* @__PURE__ */ new Set();
1253
- for (const key of stringTypedProps) {
1574
+ for (const key of topLevelStringProps) {
1254
1575
  const excludeRanges = [];
1255
- for (const other of stringTypedProps) {
1576
+ for (const other of topLevelStringProps) {
1256
1577
  if (other === key) continue;
1257
1578
  const range = findFirstTopLevelRange(actualXmlInner, other);
1258
1579
  if (range) excludeRanges.push(range);
@@ -1282,37 +1603,30 @@ function parse(xmlInner, schema, options = {}) {
1282
1603
  const originalContentMap = /* @__PURE__ */ new Map();
1283
1604
  try {
1284
1605
  const ranges = [];
1285
- for (const key of stringTypedProps) {
1286
- const r = findFirstTopLevelRange(actualXmlInner, key);
1287
- if (r && r.end > r.start) ranges.push({ ...r, key });
1606
+ for (const key of deepStringTypedProps) {
1607
+ const innerRanges = findAllInnerRanges(actualXmlInner, key);
1608
+ for (const r of innerRanges) {
1609
+ if (r.end > r.start) ranges.push({ ...r, key });
1610
+ }
1288
1611
  }
1289
1612
  if (ranges.length > 0) {
1290
1613
  const sorted = [...ranges].sort((a, b) => a.start - b.start);
1291
- const filtered = [];
1614
+ let rebuilt = "";
1615
+ let cursor = 0;
1292
1616
  for (const r of sorted) {
1293
- const last = filtered[filtered.length - 1];
1294
- if (last && r.start >= last.start && r.end <= last.end) {
1617
+ if (r.start < cursor) {
1295
1618
  continue;
1296
1619
  }
1297
- filtered.push(r);
1298
- }
1299
- if (filtered.length > 0) {
1300
- filtered.sort((a, b) => a.start - b.start);
1301
- let rebuilt = "";
1302
- let cursor = 0;
1303
- for (const r of filtered) {
1304
- if (cursor < r.start)
1305
- rebuilt += actualXmlInner.slice(cursor, r.start);
1306
- const placeholder = `__RXML_PLACEHOLDER_${r.key}__`;
1307
- const originalContent = actualXmlInner.slice(r.start, r.end);
1308
- originalContentMap.set(placeholder, originalContent);
1309
- rebuilt += placeholder;
1310
- cursor = r.end;
1311
- }
1312
- if (cursor < actualXmlInner.length)
1313
- rebuilt += actualXmlInner.slice(cursor);
1314
- xmlInnerForParsing = rebuilt;
1620
+ if (cursor < r.start) rebuilt += actualXmlInner.slice(cursor, r.start);
1621
+ const placeholder = `__RXML_PLACEHOLDER_${r.key}_${r.start}_${r.end}__`;
1622
+ const originalContent = actualXmlInner.slice(r.start, r.end);
1623
+ originalContentMap.set(placeholder, originalContent);
1624
+ rebuilt += placeholder;
1625
+ cursor = r.end;
1315
1626
  }
1627
+ if (cursor < actualXmlInner.length)
1628
+ rebuilt += actualXmlInner.slice(cursor);
1629
+ xmlInnerForParsing = rebuilt;
1316
1630
  }
1317
1631
  } catch (error) {
1318
1632
  if (options.onError) {
@@ -1336,9 +1650,35 @@ function parse(xmlInner, schema, options = {}) {
1336
1650
  throw new RXMLParseError("Failed to parse XML", cause);
1337
1651
  }
1338
1652
  const parsedArgs = domToObject(parsedNodes, schema, textNodeName);
1653
+ const restorePlaceholdersDeep = (val) => {
1654
+ if (val == null) return val;
1655
+ if (typeof val === "string") {
1656
+ if (val.startsWith("__RXML_PLACEHOLDER_")) {
1657
+ const orig = originalContentMap.get(val);
1658
+ return orig !== void 0 ? orig : val;
1659
+ }
1660
+ return val;
1661
+ }
1662
+ if (Array.isArray(val)) return val.map(restorePlaceholdersDeep);
1663
+ if (typeof val === "object") {
1664
+ const obj = val;
1665
+ const out = {};
1666
+ for (const [k, v] of Object.entries(obj)) {
1667
+ const restored = restorePlaceholdersDeep(v);
1668
+ if (k === textNodeName && typeof restored === "string") {
1669
+ out[k] = restored.trim();
1670
+ } else {
1671
+ out[k] = restored;
1672
+ }
1673
+ }
1674
+ return out;
1675
+ }
1676
+ return val;
1677
+ };
1678
+ const parsedArgsRestored = restorePlaceholdersDeep(parsedArgs);
1339
1679
  const args = {};
1340
- for (const k of Object.keys(parsedArgs || {})) {
1341
- const v = parsedArgs[k];
1680
+ for (const k of Object.keys(parsedArgsRestored || {})) {
1681
+ const v = parsedArgsRestored[k];
1342
1682
  let val = v;
1343
1683
  const propSchema = getPropertySchema(schema, k);
1344
1684
  const propType = getSchemaType(propSchema);
@@ -1448,7 +1788,7 @@ function parse(xmlInner, schema, options = {}) {
1448
1788
  }
1449
1789
  args[k] = typeof val === "string" ? val.trim() : val;
1450
1790
  }
1451
- for (const key of stringTypedProps) {
1791
+ for (const key of topLevelStringProps) {
1452
1792
  if (!Object.prototype.hasOwnProperty.call(args, key)) {
1453
1793
  const raw = extractRawInner(actualXmlInner, key);
1454
1794
  if (typeof raw === "string") {
@@ -1471,7 +1811,8 @@ function parse(xmlInner, schema, options = {}) {
1471
1811
  }
1472
1812
  try {
1473
1813
  const coerced = coerceDomBySchema(dataToCoerce, schema);
1474
- return coerced;
1814
+ const decoded = deepDecodeStringsBySchema(coerced, schema);
1815
+ return decoded;
1475
1816
  } catch (error) {
1476
1817
  throw new RXMLCoercionError("Failed to coerce by schema", error);
1477
1818
  }
@@ -1705,7 +2046,6 @@ var XMLTransformStream = class extends import_stream.Transform {
1705
2046
  continue;
1706
2047
  }
1707
2048
  }
1708
- const closingTag = `</${tagName}>`;
1709
2049
  let depth = 1;
1710
2050
  let searchStart = openTagEnd + 1;
1711
2051
  let elementEnd = -1;
@@ -2097,16 +2437,19 @@ function toContentString(nodes) {
2097
2437
  RXMLStringifyError,
2098
2438
  XMLTokenizer,
2099
2439
  XMLTransformStream,
2440
+ coerceBySchema,
2100
2441
  coerceDomBySchema,
2101
2442
  countTagOccurrences,
2102
2443
  createXMLStream,
2103
2444
  domToObject,
2104
2445
  extractRawInner,
2105
2446
  filter,
2447
+ findAllTopLevelRanges,
2106
2448
  findElementByIdStream,
2107
2449
  findElementsByClassStream,
2108
2450
  findFirstTopLevelRange,
2109
2451
  getPropertySchema,
2452
+ getSchemaType,
2110
2453
  getStringTypedProperties,
2111
2454
  parse,
2112
2455
  parseFromStream,
@@ -2119,6 +2462,8 @@ function toContentString(nodes) {
2119
2462
  stringify,
2120
2463
  stringifyNode,
2121
2464
  stringifyNodes,
2122
- toContentString
2465
+ toContentString,
2466
+ unescapeXml,
2467
+ unwrapJsonSchema
2123
2468
  });
2124
2469
  //# sourceMappingURL=index.cjs.map