Skip to content

Commit ae5b390

Browse files
authored
[core-xml] Update fxp to v4 (Azure#19898)
* Update and fix breaking changes * Bump minor * update lock
1 parent e3db6c4 commit ae5b390

File tree

4 files changed

+24
-20
lines changed

4 files changed

+24
-20
lines changed

common/config/rush/pnpm-lock.yaml

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

sdk/core/core-xml/CHANGELOG.md

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,11 @@
11
# Release History
22

3-
## 1.1.1 (Unreleased)
4-
5-
### Features Added
6-
7-
### Breaking Changes
8-
9-
### Bugs Fixed
3+
## 1.2.0 (Unreleased)
104

115
### Other Changes
126

7+
- Upgrade to `fast-xml-parser` to v4 [PR# 19898](https://github.com/Azure/azure-sdk-for-js/pull/19898)
8+
139
## 1.1.0 (2022-01-06)
1410

1511
### Other Changes

sdk/core/core-xml/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@azure/core-xml",
3-
"version": "1.1.1",
3+
"version": "1.2.0",
44
"description": "Core library for interacting with XML payloads",
55
"sdk-type": "client",
66
"main": "dist/index.js",
@@ -66,7 +66,7 @@
6666
"prettier": "@azure/eslint-plugin-azure-sdk/prettier.json",
6767
"dependencies": {
6868
"tslib": "^2.2.0",
69-
"fast-xml-parser": "^3.20.0"
69+
"fast-xml-parser": "^4.0.1"
7070
},
7171
"devDependencies": {
7272
"@azure/dev-tool": "^1.0.0",

sdk/core/core-xml/src/xml.ts

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
// Copyright (c) Microsoft Corporation.
22
// Licensed under the MIT license.
33

4-
import { j2xParser, parse, validate } from "fast-xml-parser";
4+
import { XMLBuilder, XMLValidator, XMLParser } from "fast-xml-parser";
55
import { XML_ATTRKEY, XML_CHARKEY, XmlOptions } from "./xml.common";
66

77
function getCommonOptions(options: XmlOptions) {
88
return {
9-
attrNodeName: XML_ATTRKEY,
9+
attributesGroupName: XML_ATTRKEY,
1010
textNodeName: options.xmlCharKey ?? XML_CHARKEY,
1111
ignoreAttributes: false,
12+
suppressBooleanAttributes: false,
1213
};
1314
}
1415

@@ -17,7 +18,7 @@ function getSerializerOptions(options: XmlOptions = {}) {
1718
...getCommonOptions(options),
1819
attributeNamePrefix: "@_",
1920
format: true,
20-
supressEmptyNode: true,
21+
suppressEmptyNode: true,
2122
indentBy: "",
2223
rootNodeName: options.rootName ?? "root",
2324
};
@@ -27,7 +28,7 @@ function getParserOptions(options: XmlOptions = {}) {
2728
return {
2829
...getCommonOptions(options),
2930
parseAttributeValue: false,
30-
parseNodeValue: false,
31+
parseTagValue: false,
3132
attributeNamePrefix: "",
3233
};
3334
}
@@ -39,11 +40,11 @@ function getParserOptions(options: XmlOptions = {}) {
3940
*/
4041
export function stringifyXML(obj: unknown, opts: XmlOptions = {}): string {
4142
const parserOptions = getSerializerOptions(opts);
42-
const j2x = new j2xParser(parserOptions);
43+
const j2x = new XMLBuilder(parserOptions);
4344

4445
const node = { [parserOptions.rootNodeName]: obj };
4546

46-
const xmlData: string = j2x.parse(node);
47+
const xmlData: string = j2x.build(node);
4748
return `<?xml version="1.0" encoding="UTF-8" standalone="yes"?>${xmlData}`.replace(/\n/g, "");
4849
}
4950

@@ -58,13 +59,14 @@ export async function parseXML(str: string, opts: XmlOptions = {}): Promise<any>
5859
throw new Error("Document is empty");
5960
}
6061

61-
const validation = validate(str);
62+
const validation = XMLValidator.validate(str);
6263

6364
if (validation !== true) {
6465
throw validation;
6566
}
6667

67-
const parsedXml = parse(unescapeHTML(str), getParserOptions(opts));
68+
const parser = new XMLParser(getParserOptions(opts));
69+
const parsedXml = parser.parse(unescapeHTML(str));
6870

6971
if (!opts.includeRoot) {
7072
for (const key of Object.keys(parsedXml)) {

0 commit comments

Comments
 (0)